Skip to content

Instantly share code, notes, and snippets.

:shipit:
Shippin' things, if you know what I mean

Niko Heikkilä nikoheikkila

:shipit:
Shippin' things, if you know what I mean
Block or report user

Report or block nikoheikkila

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@nikoheikkila
nikoheikkila / update_starship.sh
Last active Aug 10, 2019
Updates Starship to Latest Version
View update_starship.sh
#!/usr/bin/env bash
set -euo pipefail
post_install() {
# Checks whether user's shell configuration needs adjustment for Spaceship
# This function does not do anything when user has already activated the
# necessary configuration.
echo "Checking shell configuration"
@nikoheikkila
nikoheikkila / pipes.py
Created Jul 6, 2019
Playing with pipeable lists in Python 3
View pipes.py
from __future__ import annotations
from typing import Any, Callable, Union, Tuple
from functools import reduce
class Pipe(list):
"""Type declarations"""
Predicate = Callable[[Any], bool]
Mappable = Callable[[Any], Any]
@nikoheikkila
nikoheikkila / pipes.php
Created Jun 30, 2019
Functional Piping in PHP
View pipes.php
<?php declare(strict_types = 1);
function pipe(...$args) {
return function ($arg) use ($args) {
$reducer = function ($prev, $fn) {
return $fn($prev);
};
return array_reduce($args, $reducer, $arg);
};
@nikoheikkila
nikoheikkila / leet.js
Created Jun 22, 2019
Make text L337'er!
View leet.js
const leet = char => {
const charMap = {
'A': 4,
'E': 3,
'I': 1,
'S': 5,
'T': 7,
}
char = char.toString().toUpperCase()
@nikoheikkila
nikoheikkila / duplicate_count.py
Created Jun 8, 2019
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.
View duplicate_count.py
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 Jun 7, 2019
Cobalt2 theme for Mattermost
View cobalt2.json
{
"sidebarBg": "#15232d",
"sidebarText": "#dddddd",
"sidebarUnreadText": "#9effff",
"sidebarTextHoverBg": "#0d3a58",
"sidebarTextActiveBorder": "#15232d",
"sidebarTextActiveColor": "#ffffff",
"sidebarHeaderBg": "#15232d",
"sidebarHeaderTextColor": "#ffc600",
"onlineIndicator": "#60e019",
@nikoheikkila
nikoheikkila / changes.fish
Created May 15, 2019
Fish Shell: Generate a clean changelog between two Git revisions
View changes.fish
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
TypeScript: RGB Class Example
View color.ts
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 Feb 13, 2019
MQ example with Python and Pika
View pika.py
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 Dec 23, 2018
Reset Vivaldi browser to fresh state
View vivaldi_full_reset.sh
#!/bin/bash
set -eu
# USAGE
#
# 1. Close Vivaldi
# 2. Run this script
# 3. Start Vivaldi again
# 4. Enjoy the fresh experience
#
You can’t perform that action at this time.