Skip to content

Instantly share code, notes, and snippets.

View bullno1's full-sized avatar
💭
Set your status

Bach Le bullno1

💭
Set your status
View GitHub Profile
@bullno1
bullno1 / tail_recursion.cpp
Created October 2, 2011 06:34
Tail recursion in C++11
#include <iostream>
#include <functional>
template<typename ReturnType, typename Arg1>
struct tail_call_result
{
template<typename FuncType>
inline tail_call_result(FuncType func, Arg1 arg)
:func(func)
,argument(arg)
@bullno1
bullno1 / test.rkt
Created October 8, 2011 12:10
Yo Dawg Scheme Interpreter
(load "yo_dawg.rkt")
(define test-fib
'[(define (fib n)
(if (<= n 2)
1
(+ (fib (- n 1)) (fib (- n 2)))))
(fib 6)])
(evaluate-block test-fib)
@bullno1
bullno1 / main.cpp
Created November 10, 2011 17:11
Dual number and auto differentiation in C++
#include <iostream>
template<typename Scalar>
class DualNumber
{
public:
inline DualNumber(const Scalar& realPart, const Scalar& dualPart = Scalar())
:mReal(realPart)
,mDual(dualPart)
{
@bullno1
bullno1 / schema.js
Created July 28, 2012 14:40
JSON schema validation
number = function(x) { return getType(x) == 'number'; }
string = function(x) { return getType(x) == 'string'; }
//combinators
function or() {
var len = arguments.length;
var args = arguments;
return function(x) {
for(var i = 0; i < len; ++i) {
if(validate(args[i], x)) return true;//satisfy at least one condition
@bullno1
bullno1 / gist:9002397
Last active August 29, 2015 13:56
What does it do?
<html>
<head>
</head>
<body>
<script>
var start = "<script>";
var end = "</script>";
document.write(start + "alert('hi')" + end);
</script>
</body>
@bullno1
bullno1 / gist:9089349
Created February 19, 2014 10:19
epgsql test
erl -pa ebin/ -pa test/ -noshell -s pgsql_tests run_tests -s init stop
pgsql_tests: all_test_ (connect_test(pgsql))...*failed*
in function pgsql_tests:connect_only/2 (test/pgsql_tests.erl, line 760)
**error:{badmatch,{error,invalid_authorization_specification}}
pgsql_tests: all_test_ (connect_with_ssl_test(pgsql))...*failed*
in function pgsql_tests:'-connect_with_ssl_test/1-fun-1-'/2 (test/pgsql_tests.erl, line 79)
in call from pgsql_tests:with_connection/4 (test/pgsql_tests.erl, line 774)
**error:{badmatch,{error,{error,error,<<"42883">>,
@bullno1
bullno1 / pnc.erl
Last active August 29, 2015 13:56
Permutations & Combinations
-module(pnc).
-export([combinations/2, permutations/2]).
combinations(0, _Elements) -> [[]];
combinations(_Size, []) -> [];
combinations(Size, [Elem | Elements]) ->
[[Elem | Combination] || Combination <- combinations(Size - 1, Elements)]
++ combinations(Size, Elements).
permutations(0, _Elements) -> [[]];
-module(sql_utils).
-behaviour(gen_server).
-export([init/1, handle_call/3, handle_cast/2,
handle_info/2, terminate/2, code_change/3]).
-export([start_link/1, connect/4, prepare/1, query/3,
dirty/1, transaction/1, installed_schema_updates/0,
available_schema_updates/0, update_schema/0,
prepare_core_statements/0]).
-export_type([statement_group/0, statement_declaration/0]).
@bullno1
bullno1 / give-me-ssd.py
Last active August 29, 2015 14:01
Give me SSD
#!/usr/bin/env python
import sys, httplib, urllib, hashlib, random, json
# Relevant JS code:
#
# return e = "52297d8e78ff8aed",
# t = CryptoJS.SHA256(Math.random().toString().substr(2, 5)).toString(),
# n = "//fastestgameonearth-com.herokuapp.com",
# $.ajax({
@bullno1
bullno1 / user_reg.apib
Created September 25, 2015 07:31
katt triple backtick
# Registration
Short passwords will be rejected:
```
PUT /users/bullno1
> Content-Type: application/json
> Accept: application/json
{"password": "short"}
< 400