Skip to content

Instantly share code, notes, and snippets.

View Javran's full-sized avatar

Javran Cheng Javran

View GitHub Profile
@Javran
Javran / gist:4054438
Created November 11, 2012 10:26
4-consecutive-underlines replacement?
ulReplace :: String -> String
ulReplace ('_':'_':'_':'_':xs) = "1111" ++ xs
ulReplace (x:xs) = x :(replace xs)
ulReplace x = x
@Javran
Javran / gist:4085548
Created November 16, 2012 08:41
function/variable screening in c
#include <stdio.h>
typedef void (*ft) (const char *);
ft f;
void print1(const char *a) {
printf("#1 -> %s\n", a);
}
void print2(const char *a) {
@Javran
Javran / gist:4195626
Created December 3, 2012 15:13
COM mgmt test
#include <stack>
#include <cstdio>
class Dummy
{
public:
void Release()
{
printf("remove: %p\n", this);
}
@Javran
Javran / gist:4248329
Created December 10, 2012 04:08
weibo-plugin:眼不见心不烦
/*
个人主页升级提示
*/
div[abc="lxjts"] { display:none }
div.profile_guide {display:none}
/*
回顾微博点滴
*/
div[class="WB_right_tips S_line2"] {display:none}
#include <stdio.h>
typedef int (*callable)();
typedef struct
{
callable f;
} call_st;
@Javran
Javran / gist:4465426
Created January 6, 2013 05:26
sort csv file by column...
import Data.List
import Data.List.Split
strToTable raw = map (splitOn ",") rawRowList where
rawRowList = splitOn "\n" raw
tableToStr table = strJoin "\n" rawRowList where
rawRowList = map (strJoin ",") table
strJoin :: String -> [String] -> String
@Javran
Javran / gist:4491685
Created January 9, 2013 08:57
call functions that share one argument without indicating what the argument is repeatedly.
#include <cstdio>
void print3arg(int a, int b, int c)
{
printf("a=%d, b=%d, c=%d\n", a, b, c);
}
void print2arg(int a, int b)
{
printf("A=%d, B=%d\n", a, b);
@Javran
Javran / gist:4516960
Created January 12, 2013 09:38
Y combinator in haskell
-- plz refer to http://stackoverflow.com/questions/4273413/y-combinator-in-haskell
newtype Mu a = Mu (Mu a -> a)
y f = (\h -> h $ Mu h) (\x -> f. (\(Mu g) -> g) x $ x)
fakePower self n = if n == 0
then 1
else n*self(n-1)
truePower = y fakePower
List2D := Object clone
List2D dim := method(x, y,
target := list()
fillStrategy := "const"
default := call evalArgAt(2)
if(default type == "Block", fillStrategy := "func")
for(i, 1, y,
subTarget := list()
@Javran
Javran / gist:4690011
Last active December 12, 2015 01:18
taking advantage of lazy evaluation and functional methodology to handle user interaction.
import scala.io.Source
def getUserInputWhere(inputHint: ()=>Unit, cond: String=>Boolean) = {
Stream.continually[String]( {
inputHint()
readLine()
}).find( l => l == null || cond(l)).get
}
getUserInputWhere(