Skip to content

Instantly share code, notes, and snippets.

View selfawaresoup's full-sized avatar
💜

Esther Weidauer selfawaresoup

💜
View GitHub Profile
@selfawaresoup
selfawaresoup / screen.md
Last active August 29, 2015 14:12
Screen usage

Launch named session

screen -S <name>

Disconnect

C-a d

@selfawaresoup
selfawaresoup / typo.md
Last active August 29, 2015 14:17
script to help detect small typos in text files

Installation

Copy typo.php somewhere in your $PATH and rename it to typo (or whatever you like).

Usage

typo some_file
@selfawaresoup
selfawaresoup / datetime_millis.md
Last active August 29, 2015 14:20
Getting milliseconds from a DateTime object

Getting milliseconds from a DateTime

Task: get the millisecond component as an actual number (not a string) from a native "datetime" object of some popular dynamic languages.

Ruby

This is incomprehensible

DateTime.now.to_time.to_f % 1 * 1000
@selfawaresoup
selfawaresoup / _modular.scss
Created August 6, 2015 22:47
simplified modular scale for scss
$phi: 1.61803398874989; //"Golden Ratio"
$base-size: 1rem;
@function size($n) {
$size: $base-size;
@if $n > 0 {
@for $i from 1 through $n {
$size: $size * $phi;
}
@selfawaresoup
selfawaresoup / rewrite.php
Created August 24, 2015 13:52
URL rewriting with exception for static files in PHP's built-in web server
<?php
if (preg_match('/\.(?:png|jpg|jpeg|gif|js|css)$/', $_SERVER["REQUEST_URI"])) {
return false;
} else {
include __DIR__ . '/index.php';
}
@selfawaresoup
selfawaresoup / fib.clj
Last active September 8, 2015 22:32
fibonacci numbers in clojure, lazily evaluated, using thread macros
(defn fib [n]
(->>
(->
(fn [[a b]] [b (+' a b)])
(iterate [1 1]))
(map first)
(take n)))
(fib 5) ;; (1 1 2 3 5)
@selfawaresoup
selfawaresoup / count.php
Created June 13, 2013 12:58
The builtin count() in PHP is so simple, it can't be broken, right?
<?php
// All these expressions are (bool)true:
count([]) === 0; // Ok, that's expected.
count(true) === 1; // Wait, I can count non-arrays? What does this even mean?
count(false) === 1; // WTF?
count(0) === 1; // yeah, obviously …
count("") === 1; // I'm, starting to see a pattern.
@selfawaresoup
selfawaresoup / duplicates.sh
Created June 29, 2013 21:33
Remove duplicate entries from OSX Finder context menu
/System/Library/Frameworks/CoreServices.framework/Versions/A/Frameworks/LaunchServices.framework/Versions/A/Support/lsregister -kill -r -domain local -domain user
@selfawaresoup
selfawaresoup / files.md
Last active December 19, 2015 03:49
Generate large files for testing

Generate 1GB files quickly (instantly):

dd if=/dev/zero of=test.img bs=1024 count=0 seek=$[1024*1024]

Generate 1GB files with realistic copy delay:

dd if=/dev/zero of=test.img bs=1024 coun=$[1024*1024] seek=0

@selfawaresoup
selfawaresoup / textops.md
Last active December 19, 2015 03:49
Text operations in shell scripts

Extract one specific line with AWK

  • awk 'NR==40550{print;exit}' <file>

Extract line 40550 to 40601:

  • sed '40602q;40550,40601!d' <file>
  • awk 'NR==40550,NR==40601' <file>

Extract line 60451 and 68451:

  • sed -n '68452q;60451p;68451p' <file>
  • awk 'FNR==60451 || FNR==68451 {print}; FNR==68452 {exit}'