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 'benchmark/ips' | |
| START = 1 | |
| FINISH = 1_000_000 | |
| HALF = FINISH / 2 | |
| Benchmark.ips do |x| | |
| x.report('lazy') do | |
| (START..FINISH).lazy.include?(HALF) | |
| 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
| let sum lst = | |
| let rec aux acc rest = match rest with | |
| | [] -> acc | |
| | x::xs -> aux (x+acc) xs in | |
| aux 0 lst;; | |
| sum [3;1;4;1;5;9];; | |
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 "$0 [FILE] -- print a message to STDOUT or FILE" >&2 | |
| if [ -z $1 ]; then | |
| exec 3>&1 # stdout | |
| else | |
| exec 3>"$1" # file | |
| 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
| (defun make-password () | |
| (interactive) | |
| (let* ((cmd "egrep '{6,}' /usr/share/dict/words | shuf -n 4 | tr \"\\n\" ' '") | |
| (pass (replace-regexp-in-string " $" "" (shell-command-to-string cmd)))) | |
| (message pass) | |
| (kill-new pass))) |
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 Book | |
| include Neo4j::ActiveNode | |
| property :title | |
| has_many :in, :spaces, rel_class: :BookAuthor | |
| end | |
| class Author | |
| include Neo4j::ActiveNode |
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 StringStripper | |
| def strip(*keys) | |
| before_validation do | |
| keys.each do |k| | |
| self[k] = self[k].to_s.gsub(/[[:space:]]/, '') if self[k].present? | |
| end | |
| end | |
| 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
| def foo(arg1:, arg2: :foo) | |
| puts "arg1 = %s, arg2 = %s" % [arg1, arg2] | |
| end | |
| foo(arg1: "HI") | |
| foo(arg1: "HI", arg2: "MOM") | |
| foo(**{arg1: "HI", arg2: "MOM"}) |
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 jm/yeller () | |
| (interactive) | |
| (set-background-color "#FFFFDD")) | |
| (defun jm/minty () | |
| (interactive) | |
| (set-background-color "#F0FFF0")) |
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 Book | |
| include Neo4j::ActiveNode | |
| property :title | |
| has_many :in, :spaces, rel_class: :BookAuthor | |
| end | |
| class Author | |
| include Neo4j::ActiveNode |
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
| $grid = Array.new(10, "X").map { |r| Array.new(10, "X") } | |
| def $grid.print | |
| puts map(&:join) | |
| end | |
| def $grid.draw(row, col, size: 2) | |
| bounds = $grid.length | |
| fail "out of bounds #{row}+#{size} > #{bounds}" if row+size > bounds | |
| shape = ' ' |