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
| def mm(s): | |
| in_to_mm = lambda i: i*25.4 | |
| delim = " x " | |
| ss = s.replace(" ", "").lower().split(delim.replace(" ", "")) | |
| dims_in = map(float, ss) | |
| dims_mm = map(in_to_mm, dims_in) | |
| return reduce(lambda l,r: l+delim+r, map(str, dims_mm),"")[len(delim):-1] |
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 Integrator { | |
| final float DAMPING = 0.5f; | |
| final float ATTRACTION = 0.2f; | |
| float value; | |
| float vel; | |
| float accel; | |
| float force; | |
| float mass = 1; |
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
| def _(s): | |
| return eval(("lambda " + s).replace("=>", ":")) | |
| # >>> _("x => str(x)")(42) == "42" | |
| True |
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 FizzBuzz | |
| def initialize | |
| @data = (1..100).map { |n| | |
| out = ((n%3 == 0) ? "Fizz" : "") + ((n%5 == 0) ? "Buzz" : "") | |
| (out == "") ? n.to_s : out | |
| } | |
| end | |
| def tableView(tableView, cellForRowAtIndexPath: indexPath) | |
| @reuse_identifier ||= "CELL_IDENTIFIER" |
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
| i() { | |
| if [[ -a tmp/isolate ]] ; then | |
| echo "\$ rake isolate:sh[\"$*\"]" | |
| rake isolate:sh["$*"] | |
| else | |
| if [[ -a Gemfile ]] ; then | |
| echo "\$ bundle exec[$*]" | |
| bundle exec $* | |
| else | |
| echo "You must be at the root of a rails app that uses either Bundler or Isolate." |
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
| def reduce(f:(Int,Int)=>Int, xo:Int, lst: List[Int]): Int = { | |
| if (lst.length == 1) f(xo, lst.head) | |
| else f(reduce(f, xo, lst.tail), lst.head) | |
| } |
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
| # a 'revision' is a branch, commit or tag | |
| stage() { | |
| CWD=`pwd` | |
| DIR=${CWD##*/} | |
| if [ "$*" == "" ]; then | |
| echo "We need a revision to deploy. E.g. master" | |
| return 1 | |
| fi |
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
| git branch | grep -e "^\*" | sed 's/^\* //g' | sed 's/\-/ /g' | awk '{print $(NF)}' |
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
| ;; (quoted-from (short (story (title (and robot baby))))) | |
| (setq line "(Implies (Non-literal-interpretation x) y) (Value (Obey x) (* 0.5 (Value (Obey y)))))") | |
| "(Implies (Non-literal-interpretation x) y) (Value (Obey x) (* 0.5 (Value (Obey y)))))" | |
| ;; check if expr (list of chars of some expression) is balanced | |
| (defun balanced (expr) | |
| (defvar lparen (string-to-char "(")) | |
| (defvar rparen (string-to-char ")")) | |
| (defun is-open (c) (eq lparen c)) |
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
| import sys | |
| input_number = sys.stdin.readline() | |
| print(float(input_number)*0.5) |