Skip to content

Instantly share code, notes, and snippets.

View nikoheikkila's full-sized avatar
🇺🇦
Stand with Ukraine

Niko Heikkilä nikoheikkila

🇺🇦
Stand with Ukraine
View GitHub Profile
@nikoheikkila
nikoheikkila / duplicate_count.py
Created June 8, 2019 11:29
Write a function that will return the count of distinct case-insensitive alphabetic characters and numeric digits that occur more than once in the input string.
def duplicate_count(text: str) -> int:
"""Write a function that will return the count of distinct case-insensitive
alphabetic characters and numeric digits that occur more than once in the
input string.
The input string can be assumed to contain only alphabets
(both uppercase and lowercase) and numeric digits.
"abcde" -> 0 # no characters repeat more than once
"aabbcde" -> 2 # 'a' and 'b'
@nikoheikkila
nikoheikkila / cobalt2.json
Last active June 7, 2019 13:42
Cobalt2 theme for Mattermost
{
"sidebarBg": "#15232d",
"sidebarText": "#dddddd",
"sidebarUnreadText": "#9effff",
"sidebarTextHoverBg": "#0d3a58",
"sidebarTextActiveBorder": "#15232d",
"sidebarTextActiveColor": "#ffffff",
"sidebarHeaderBg": "#15232d",
"sidebarHeaderTextColor": "#ffc600",
"onlineIndicator": "#60e019",
@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]