Skip to content

Instantly share code, notes, and snippets.

View ankr's full-sized avatar
🎯
Focusing

Andreas ankr

🎯
Focusing
View GitHub Profile
@ankr
ankr / cecho.md
Created February 7, 2015 12:16
Colorized output in shell and bash scripts.

Colored output in bash script

Implementation varies between platforms, see below.

Usage

cecho "Hello world" yellow

White terminal?

This script assumes your terminal has a black background, to use with white terminals replace ;40m with ;47m for each color. (There are more colors, try them out!)

@ankr
ankr / slugify.php
Last active August 29, 2015 14:18
PHP function to turn a string into a slug. Will transliterate characters and replace whitespace with `-`.
<?php
// @see http://stackoverflow.com/a/13331948/1640765
function slugify($str) {
$str = transliterator_transliterate("Any-Latin; NFD; [:Nonspacing Mark:] Remove; NFC; [:Punctuation:] Remove; Lower();", $str);
$str = preg_replace('/\s+/', '-', $str);
return trim($str, '-');
}
@ankr
ankr / danish_apis.md
Last active January 29, 2024 13:22
List of various Danish API services.
const ordinal = (n) => {
const s = ['th', 'st', 'nd', 'rd'];
const m = n % 100;
return n + (s[(m - 20) % 10] || s[m] || s[0]);
};
@ankr
ankr / scrcap.md
Last active March 25, 2020 10:06
Simple script for taking a drag-n-drop screenshot on OSX and upload it to your private server.

scrcap

Simple script to taking drag-n-drop screenshots on OSX and upload them to your own server.

  1. First create a new bash script with the following content:
#!/bin/bash

# Use timestamp to generate "unique" filename
filename=$(date +%s).png
@ankr
ankr / debug.go
Created August 22, 2018 08:16
Go debug function that includes filename and line number
package debug
import (
"fmt"
"runtime"
"strings"
)
func Debug(data interface{}) {
_, file, line, ok := runtime.Caller(1)