Skip to content

Instantly share code, notes, and snippets.

View nikoheikkila's full-sized avatar
:electron:
Nice to meet you!

Niko Heikkilä nikoheikkila

:electron:
Nice to meet you!
View GitHub Profile
@nikoheikkila
nikoheikkila / changes.fish
Last active April 5, 2020 05:01
Fish Shell: Generate a clean changelog between two Git revisions
function changes -d "Generate a Markdown changelog from conventional commits" -a target
# Use fallback variables if no arguments were given.
if test (count $argv) -eq 0
set target master
end
# Include commit message, author name, and the short hash in parentheses.
set -l log_format "%s (_%aN_) (%h)"
@nikoheikkila
nikoheikkila / color.ts
Created May 4, 2019 21:00
TypeScript: RGB Class Example
export type Difference = (a: number, b: number) => number
export default class Color {
protected red: number
protected green: number
protected blue: number
protected opacity?: number
static HEX_MIN = 0
static HEX_MAX = 255
@nikoheikkila
nikoheikkila / pika.py
Created February 13, 2019 17:33
MQ example with Python and Pika
from pika import BlockingConnection
from pika.exceptions import AMQPConnectionError, AMQPChannelError
class MQ:
def __init__(self):
self.connection = BlockingConnection()
self.channel = self.connection.channel()
@nikoheikkila
nikoheikkila / vivaldi_full_reset.sh
Last active December 23, 2018 11:22
Reset Vivaldi browser to fresh state
#!/bin/bash
set -eu
# USAGE
#
# 1. Close Vivaldi
# 2. Run this script
# 3. Start Vivaldi again
# 4. Enjoy the fresh experience
#
@nikoheikkila
nikoheikkila / CarbonTest.php
Created September 16, 2018 12:58
Quick Tip: Faking Dates in PHP with Carbon
// Set test date to 12:00 on 18th June, 2018
$testDate = Carbon::create(2018, 6, 18, 12);
Carbon::setTestNow($testDate);
// Execute the logic
BusinessClass::doStuff();
// Check the results
$this->assertDatabaseHas('stuff', [
// The data you need...
@nikoheikkila
nikoheikkila / LinkedList.js
Last active September 13, 2018 14:04
Linked lists in Javascript
/**
* Linked lists in Javascript
* @see https://dev.to/ryanfarney3/intro-to-linked-lists-in-js-19b4
*/
class Node {
constructor(data, next = null) {
this.data = data;
this.next = next;
@nikoheikkila
nikoheikkila / currencyFormatter.js
Created May 22, 2018 17:31
How to easily format currency in Javascript without external libraries
class Payment {
constructor(amount, currency) {
this.amount = amount;
this.currency = currency;
}
get localeMap() {
return {
USD: "en-US",
@nikoheikkila
nikoheikkila / weather.fish
Created March 3, 2018 09:29
Weather Tool for Fish Shell using wttr.in API
function weather -d "Prints weather information for the given location"
if set -q $argv[1]
set location $argv[1]
else
set location "Jyväskylä"
end
# Parse language information from current locale
set -l language (string split "_" -- $LANG)[1]
@nikoheikkila
nikoheikkila / README.md
Created February 10, 2018 10:37
Twitter Blocklist

Twitter Blocklist by @nikoheikkila

How to use

  1. Save the CSV file on your machine
  2. Go to your Twitter Settings > Blocked page
  3. Click Advanced Options
  4. Click Import a list
  5. If the preview looks good, accept and save
@nikoheikkila
nikoheikkila / .php_cs.dist
Created January 24, 2018 13:33
PHP CS Fixer Configuration for VS Code (and other editors)
<?php
$config = PhpCsFixer\Config::create()
->setRiskyAllowed(true)
->setRules([
'@PSR2' => true,
'align_multiline_comment' => ['comment_type' => 'all_multiline'],
'array_syntax' => ['syntax' => 'short'],
'blank_line_after_namespace' => true,
'blank_line_after_opening_tag' => false,