Skip to content

Instantly share code, notes, and snippets.

View ankr's full-sized avatar
🎯
Focusing

Andreas ankr

🎯
Focusing
View GitHub Profile
@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)
@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
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 / danish_apis.md
Last active January 29, 2024 13:22
List of various Danish API services.
@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 / 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!)

ASCII TABLE

Dec Hex Oct Binary Char Description
0000 0000 0000 00000000 NUL Null Character
0001 0001 0001 00000001 SOH Start of Header
0002 0002 0002 00000010 STX Start of Text
0003 0003 0003 00000011 ETX End of Text
0004 0004 0004 00000100 EOT End of Transmission
0005 0005 0005 00000101 ENQ Enquiry
@ankr
ankr / gist:f85bbaf5c2fc88e60470
Last active August 29, 2015 14:03
No `git add .`
git() {
if [[ $1 == 'add' ]] && [[ $2 == '.' ]]; then
echo "No no no no ... NO!!"
else
command git "$@"
fi
}
@ankr
ankr / debug.php
Created June 13, 2014 08:03 — forked from kimegede/debug.php
<?php
function debug($data) {
$bt = debug_backtrace();
$bt = array_shift($bt);
$data = print_r($data, true);
$html = <<<HTML
<div class="debug-output">
%s
@ankr
ankr / .editorconfig
Last active December 3, 2020 12:50
Base editorconfig for new projects
# Base editorconfig for new projects
root = true
[*]
end_of_line = lf
indent_style = space
tab_width = 4
charset = utf-8
trim_trailing_whitespace = true