This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #! /bin/sh | |
| die() { | |
| echo $1 | |
| exit 1 | |
| } | |
| ( | |
| flock -n 9 || die "couldn't acquire ze lock" | |
| echo "starting ..." | |
| sleep 10 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| $ cat test.csv | |
| cat,dog,mouse | |
| up,down,left,right | |
| red,green,blue | |
| $ cat test.csv | column -t -s, | |
| cat dog mouse | |
| up down left right | |
| red green blue |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| module Enumerable | |
| def avg | |
| reduce(0.0, :+) / length | |
| end | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/sh | |
| # via: http://capotej.com/blog/2012/10/07/an-embedded-key-value-store-for-shell-scripts/ | |
| DBFILE=example.db | |
| put(){ | |
| echo "export kv_$1=$2" >> $DBFILE | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // tested in chrome | |
| link = document.createElement("a") | |
| // <a></a> | |
| link.setAttribute("href", "https://whatever.com:3000/some-page?foo=bar#baz") | |
| // undefined | |
| link.href | |
| // https://whatever.com:3000/some-page?foo=bar#baz | |
| link.protocol | |
| // https: | |
| link.host |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| DROP FUNCTION IF EXISTS shorten; | |
| DELIMITER $$ | |
| CREATE FUNCTION shorten(s VARCHAR(255), n INT) RETURNS VARCHAR(255) | |
| BEGIN | |
| IF ISNULL(s) THEN | |
| RETURN ''; | |
| ELSEIF n < 15 THEN | |
| RETURN LEFT(s, n); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # alternatively | |
| class Dog | |
| def bark | |
| puts "bark bark" | |
| end | |
| end | |
| fido = Dog.new | |
| rex = Dog.new |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # round 1! => nonblocking example | |
| [process a] $ flock -en sleeper.lock ./sleeper.sh | |
| time to sleep ... | |
| [process b] $ flock -en sleeper.lock ./sleeper.sh | |
| # ^ will exit b/c of n switch: "Fail (with an exit code of 1) | |
| # rather than wait if the lock cannot be immediately acquired. | |
| ... waking up # <= process a returning | |
| # round 2! => blocking example |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/sh | |
| echo "you passed me $# args" | |
| echo "pid = $$" | |
| echo "and I am $0" | |
| for a in $@ | |
| do | |
| echo $a | |
| done |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| require 'net/http' | |
| require 'uri' | |
| require 'io/console' | |
| puts "Enter in a github username:" | |
| gh_username = gets.chomp | |
| puts "Enter in the github user password (hidden):" | |
| gh_password = STDIN.noecho(&:gets).chomp | |
| uri = URI.parse('https://api.github.com/user') |