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
| function dine() { | |
| local tmpfile | |
| # tmpfile=$(mktemp -p "${TMPDIR:-/tmp}" "dine-XXXX.${1:-tmp}") | |
| tmpfile=$(mktemp "dine-XXXX.${1:-tmp}") | |
| dospath=$(cygpath -ma "$tmpfile") | |
| echo "$tmpfile -> $dospath" | |
| touch "$tmpfile" | |
| tee "$tmpfile" | |
| if [[ -s "$tmpfile" ]] ; then | |
| Emacsclient -n "$dospath" |
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
| zmodload zsh/datetime | |
| function uptime() { | |
| reboot_time=$(net statistics server | awk '/Statistics since/{print $3, $4, $5}') | |
| strftime -r -s reboot_secs '%d/%m/%Y %H:%M:%S %p' "$reboot_time" | |
| (( uptime = $EPOCHSECONDS - $reboot_secs )) | |
| (( up_days = uptime / 86400 )) | |
| (( up_hours = (uptime % 86400) / 3600 )) | |
| (( up_minutes = ((uptime % 86400) % 3600 ) / 60)) | |
| (( up_seconds = ((uptime % 86400) % 3600 ) % 60)) |
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
| (defun bayes-transform-form (PB!A PA PB) | |
| "Return a form to compute P(A|B) | |
| given P(B|A), P(A) and P(B)." | |
| `(/ (* ,(or PB!A 'PB!A) ,(or PA 'PA)) | |
| ,(or PB 'PB))) | |
| (defun total-probability-complementary (PA!B PA!notB PB) | |
| "Return a form to compute the total probability of | |
| complementary events P(B) = P(A|B)P(B) + P(A|!B)P(!B)." | |
| `(+ (* ,(or PA!B 'PA!B) |
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
| (dolist (i (number-sequence 1 9)) | |
| (dolist (j (number-sequence 1 9)) | |
| (insert (format "%2d " (* i j)))) | |
| (insert "\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
| " Vim global plug-in for running git grep. | |
| " Last Change: Wed 2 Dec 2009 16:46:13 AEST | |
| " Maintainer: Matt Curtis <[email protected]> | |
| " License: This file is placed in the public domain. | |
| " Notes: stolen from http://vim.wikia.com/wiki/Git_grep | |
| if exists('g:git_grep') | |
| finish | |
| endif |
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
| (defmacro are (form &rest forms) | |
| "Evaluate FORM, then a list of FORMS with should. If any return | |
| nil, abort the current test as failed. | |
| Returns the value of the last form evaluated." | |
| (let ((result (make-symbol "result"))) | |
| `(progn | |
| (setq ,result (should ,form)) | |
| (unless (null ',forms) | |
| (setq ,result (are ,@forms))) |
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
| # http://twitter.com/#!/mfeathers/status/61229026034978817 | |
| `git log | grep "^Date"`.split($/).map { |line| line.split(' ')[4].split(':')[0] }.group_by { |x| x }.map {|k,v| [k,v.length] } |
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
| class Tree | |
| attr_accessor :children, :name | |
| def initialize(tree, name='root') | |
| @name = name | |
| @children = tree.map do |k,v| | |
| Tree.new(v, k) | |
| 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
| # module is awesome! | |
| module Enumerable; | |
| def histogram; | |
| groups = group_by {|i| i}; | |
| (0..max).map {|bin| (groups[bin] || []).count} | |
| end | |
| end |