This file contains 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 'pg' | |
PGDB = PG.connect(host: '/tmp', dbname: 'mydb') | |
PGDB.type_map_for_results = PG::BasicTypeMapForResults.new(PGDB) | |
class Hash | |
def symbolize_keys | |
inject({}) { |m, kv| v = kv[1]; | |
m[kv[0].to_sym] = v.is_a?(Hash) ? v.symbolize_keys : v; m } | |
end | |
end |
This file contains 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
#include <iostream> | |
using namespace std; | |
auto upto(int& beg, int& end) -> decltype(std::function<int()>()) { | |
return [&]() { | |
if (beg <= end) { | |
return beg++; | |
} | |
return 0; |
This file contains 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
package stack | |
import "fmt" | |
// Stack is a LIFO data structure | |
type Stack struct { | |
len int | |
top *node | |
} |
This file contains 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 GuessTheNumber where | |
import System.Random | |
startGame :: IO () | |
startGame = do | |
let tries = 5 | |
num <- randomRIO (0, 9) :: IO Int | |
makeGuess num tries |