Skip to content

Instantly share code, notes, and snippets.

View rssh's full-sized avatar

Ruslan Shevchenko rssh

View GitHub Profile
@rssh
rssh / gist:506ae586157b03cbf0ef
Created July 21, 2014 16:23
Unreactive pseudocode 1
def listUsers(r: Request): RequestResult = listForm.bind(request){
success(form) => Ok (ToJson(
users.filter(_.name contains form.q).page(form.offset,form.limit)
) )
failure(f,message, ex) => Error(403, message)
}
@rssh
rssh / gist:a761b926335b98d84987
Last active August 29, 2015 14:04
example of thrift definition
struct ProfileInfo
{
1: required string uid;
2: optional string firstName;
3: optional string middleName;
4: optional string lastName;
5: optional string email;
6: optional string phone;
7: optional string addrPostal;
}
@rssh
rssh / OSDN2013_9_nemerle
Created October 10, 2013 10:33
Definition of do/while in Nemerle
macro dowhile (cond, body)
syntax ("do", body, "while", "(", cond, ")")
{
def loop = Nemerle.Macros.Symbol (Util.tmpname ("do_while"))
<[
(($("_N_break" : global) : {
def $(loop : name) () : void {
($("_N_continue" : global) : { $body }) : void;
when ($cond)
$(loop : name) ();
@rssh
rssh / OSDN2013_8_tcl
Last active December 25, 2015 04:19
Implementation fo do/wile in tcl (fragment)
proc do {body whileword condition} {
global errorInfor errorCode
if {![string equal $whileword while]} {
error "should be \"do body while condition\""
}
while {1} {
set code [catch {uplevel 1 $body} message]
if { !ok( $code) } {
return handleBreak($code, $body, $message)
}
@rssh
rssh / OSDN_8_tcl
Created October 10, 2013 09:50
example of tcl expression with 'own' do-while
set x 1
do {
set d [expr ($s/$x - $x)/2]
while { $d != 0 }
@rssh
rssh / OSDN_7_rewriting
Created October 10, 2013 08:44
example of rewriting rules
sqrtd(s,x,0) -> x
sqrtd(s,x,d) -> sqrt(s, x+d, (s/x - x)/2 )
sqrt(s) -> sqrtd(s,1,(s-1)/2)
int x = 1
int d = 1
while(d != 0) {
d = (s/x - x)/2
x = x+d
}
@rssh
rssh / OSDN2013_Forth_5
Created October 10, 2013 05:57
example of getting square root in forth
: sqrt-closer (square guess -- square guess adjustment) 2dup / over - 2 / ;
: sqrt ( square -- root ) 1 begin sqrt-closer dup while + repeat drop nip ;
@rssh
rssh / OSSN2013_4_forth1
Created October 9, 2013 22:03
Example of expression on forth language
0 10 1 DO i + LOOP;
@rssh
rssh / OSDN2013_3_vars
Created October 9, 2013 21:55
simle program, where variable names changes to undescore. (illustration for article)
int _ = 10;
int _ = 0;
for(int _ = 1; _ < _; ++x) {
_ += _;
}