Skip to content

Instantly share code, notes, and snippets.

Kelvin Hu sillykelvin

Block or report user

Report or block sillykelvin

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@sillykelvin
sillykelvin / tmux-dev.sh
Created Oct 9, 2017
A tmux script to restore work environment quickly after reboot
View tmux-dev.sh
#!/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
A callback dispatcher with generic types
View generic_dispatcher.cpp
#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);
View heap_sort.cpp
#include <algorithm>
#include <iostream>
using namespace std;
#define ARR_LEN(arr) (sizeof(arr) / sizeof(arr[0]))
struct element {
int id;
int score;
View tmux_cheatsheet.markdown

tmux cheatsheet

As configured in my dotfiles.

start new:

tmux

start new with session name:

View openssl.py
#!/usr/bin/python
# Quick and dirty demonstration of CVE-2014-0160 by Jared Stafford (jspenguin@jspenguin.org)
# The author disclaims copyright to this source code.
import sys
import struct
import socket
import time
import select
View delegate.hpp
#ifndef DELEGATE_HPP_INCLUDED
#define DELEGATE_HPP_INCLUDED
#include <functional>
#include <vector>
// general case
template<typename R, typename... Args>
class delegate
{
@sillykelvin
sillykelvin / sohu_crawler.js
Last active Aug 9, 2016
A node.js script for sohu video downloading
View sohu_crawler.js
#!/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 Dec 29, 2015
Solve Monty Hall problem (AKA Three Door problem)
View main.cpp
#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 Nov 19, 2013
The example of member access operator -> overloading.
View operator_overloading.cpp
#include <iostream>
struct Origin {
int a;
};
struct Wrapper {
Origin *orig;
Origin *operator->() const {
return orig;
@sillykelvin
sillykelvin / main.c
Created Nov 6, 2013
A sample nmake project
View main.c
#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);
You can’t perform that action at this time.