Skip to content

Instantly share code, notes, and snippets.

View sillykelvin's full-sized avatar

Kelvin Hu sillykelvin

View GitHub Profile
@sillykelvin
sillykelvin / XIRR.js
Created October 10, 2019 11:07 — forked from ghalimi/XIRR.js
XIRR Function
// Copyright (c) 2012 Sutoiku, Inc. (MIT License)
// Some algorithms have been ported from Apache OpenOffice:
/**************************************************************
*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
@sillykelvin
sillykelvin / tmux-dev.sh
Created October 9, 2017 08:35
A tmux script to restore work environment quickly after reboot
#!/bin/sh
tmux new-session -d -s dev -n fkgfw 'sslocal -v -c own.conf'
tmux new-window -n src -c '/data/project/src'
tmux new-window -n dist -c '/data/project/dist'
tmux new-window -n build -c '/data/project/src/build'
tmux new-window -n tmp -c '/home/kelvin/tmp'
tmux new-window -n vm1 'ssh ubuntu@192.168.2.101'
tmux new-window -n vm2 'ssh ubuntu@192.168.2.102'
@sillykelvin
sillykelvin / generic_dispatcher.cpp
Last active May 11, 2017 07:02
A callback dispatcher with generic types
#include <memory>
#include <iostream>
#include <unordered_map>
// this is useful when dealing with google protobuf messages, what
// you get in your message callback is a google::protobuf::Message
// type, however, what you need is a concrete type, something like
// LoginRequest/LoginResponse, so you have to do the following:
//
// const LoginRequest *req = static_cast<const LoginRequest*>(msg);
@sillykelvin
sillykelvin / sohu_crawler.js
Last active August 9, 2016 08:37
A node.js script for sohu video downloading
#!/usr/bin/env node
var fs = require('fs');
var http = require('http');
var request = require('request');
var urlListFile = 'url.list';
if (!fs.existsSync(urlListFile)) {
@sillykelvin
sillykelvin / main.cpp
Last active December 29, 2015 14:49
Solve Monty Hall problem (AKA Three Door problem)
#include <iostream>
#include <random>
typedef std::mt19937 EngineType;
typedef std::uniform_int_distribution<std::mt19937::result_type> GeneratorType;
bool GetIt(EngineType& engine, const GeneratorType& generator3, bool change) {
int correct_door = generator3(engine);
int first_choice = generator3(engine);
@sillykelvin
sillykelvin / operator_overloading.cpp
Created November 19, 2013 16:22
The example of member access operator -> overloading.
#include <iostream>
struct Origin {
int a;
};
struct Wrapper {
Origin *orig;
Origin *operator->() const {
return orig;
@sillykelvin
sillykelvin / main.c
Created November 6, 2013 08:02
A sample nmake project
#include <stdio.h>
#include "share1.h"
#include "share2.h"
#include "static.h"
int main() {
printf("hello world\n");
int a = 4;
int b = 2;
printf ("a: %d, b: %d\n", a, b);
@sillykelvin
sillykelvin / gist:6349027
Created August 27, 2013 02:30
Add two numbers presented as two lists, an exercise in Lisp-cn google group. See https://groups.google.com/forum/#!topic/lisp-cn/AVEjxh0A5r0
(define (list-add lst1 lst2)
(define (iter a1 a2 carry ret)
(cond ((and (null? a1) (null? a2))
(if carry
(append ret '(1))
ret))
((null? a1)
(if carry
(iter '(1) a2 #f ret)
(append ret a2)))
@sillykelvin
sillykelvin / answer-crack.sh
Created November 8, 2012 16:35
answer-crack
#!/bin/zsh
i=0
while [ $i -le 800 ]; do
echo trying the $i times...
i=$(($i + 1))
md5=$(curl http://yuyang.co/game/\?width\=$i\&k\=0eb46665addf43389ae950050f787a45 | md5sum)
#echo $md5
if [ "$md5" != "c92e32594fd6558d6e1df9ab77daca42 -" ]; then
echo width is found: $i
break
@sillykelvin
sillykelvin / heap_sort.cpp
Created December 23, 2014 12:36
C++ heap sort
#include <algorithm>
#include <iostream>
using namespace std;
#define ARR_LEN(arr) (sizeof(arr) / sizeof(arr[0]))
struct element {
int id;
int score;