( Source: the mongoid cheatsheet )
class User
include Mongoid::Document
| p(n-1, k) + p(n-1,k-1) + p(n-1,k-2) | |
| #include <stdio.h> | |
| int pascal(int n, int k) { | |
| int aux(int n, int k, int(*c)(int)) { | |
| int c1(int ret1) { | |
| int c2(int ret2) { | |
| int c3(int ret3) { |
| ### Eliminate consecutive duplicates of list elements. ### | |
| compress [] = [] | |
| compress (x:xs) = [x] ++ (compress $ dropWhile (== x) xs | |
| ### Flatten a nested list structure. ### | |
| flatten :: NestedList a -> [a] | |
| flatten (Elem a ) = [a] | |
| flatten (List (x:xs)) = flatten x ++ flatten (List xs) |
| """Translated from Haskell: | |
| let sieve(p:xs) = p : sieve (filter (\ x -> x `mod` p /= 0) xs) in sieve [2..] | |
| """ | |
| from itertools import ifilter | |
| def ints(k): | |
| while True: | |
| yield k | |
| k+=1 |
| c_cyan=`tput setaf 6` | |
| c_sgr0=`tput setaf 14` | |
| parse_git_branch() { | |
| git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/(\1)/' | |
| } | |
| PS1="\n\[\e[30;1m\]\[\016\]\[\017\](\[\e[34;1m\]\w\[\e[30;1m\])-(\[\e[1;33m\]\@ \d\[\e[30;1m\])-(\[\e[32;1m\]\$(ls -1 | wc -l | sed 's: ::g') files, \$(ls -lah | grep -m 1 total | sed 's/total //')b\[\e[30;1m\]):\[${c_cyan}\]\e[30;1m\](\e[1;31m\]\$(parse_git_branch)\e[30;1m\]) \[\e[0m\]\n\[\e[1;33m\]#\[${c_sgr0}\] " |
( Source: the mongoid cheatsheet )
class User
include Mongoid::Document
| # First get a baseline measurement | |
| cd /your/rails/app | |
| time script/rails runner "puts 1" | |
| # Install a patched ruby | |
| curl https://gist.github.com/raw/996418/e2b346fbadeed458506fc69ca213ad96d1d08c3e/require-performance-fix-r31758.patch > /tmp/require-performance-fix.patch | |
| rvm install ruby-head --patch /tmp/require-performance-fix.patch -n patched | |
| # ... get a cup of tea, this took about 8 minutes on my MBP | |
| # Get a new measurement |
| function VMCheney (instructionArray, heapSlot) | |
| { | |
| this.instructionArray = instructionArray; | |
| this.heapSlot = heapSlot; | |
| } | |
| VMCheney.prototype.HEAP_SIZE = 400; | |
| VMCheney.prototype.SPACE_SIZE = 200; | |
| VMCheney.prototype.peek = function (address, size) |
| defmodule Chain do | |
| # There are a couple of interesting things to note in this example. | |
| # Take a look at the 'counter' function: | |
| # It takes in a pid, NOT 'n'. | |
| # 'n' will be received in the form of a message (i.e. pid <- msg ) | |
| # In a sense, we are 'loading/setting up' the function first. | |
| def counter(next_pid) do | |
| receive do | |
| n -> |
| defmodule Echo do | |
| def echo(token, caller_pid) do | |
| IO.puts "Sending #{inspect token} to #{inspect caller_pid}" | |
| caller_pid <- { caller_pid, token } | |
| end | |
| end | |
| defmodule Receiver do | |
| def report(times) do | |
| Enum.map(1..times, |