Skip to content

Instantly share code, notes, and snippets.

@hanji
hanji / hashjoin.cpp
Created December 19, 2011 06:54
find the difference of two datasets
#include <cstdint>
#include <cstdlib>
#include <ctime>
#include <iostream>
#include <vector>
#include <unordered_set>
#include <boost/random.hpp>
#include <boost/random/mersenne_twister.hpp>
#include <boost/random/uniform_int_distribution.hpp>
#include <boost/random/variate_generator.hpp>
@hanji
hanji / smart_pointer_deleter_is_broken.cpp
Created December 21, 2011 05:41
smart pointer deleter is broken
/**
* smart_pointer_deleter_is_broken.cpp
* (c) 2011 Ji Han
* the specification of std::unique_ptr/std::shared_ptr is broken--
* default constructed Deleter has no way to pass size_type n to Alloc::deallocate(T*, size_type)
*/
#include <cstdlib>
#include <algorithm>
#include <iostream>
@hanji
hanji / timer.c
Created December 31, 2011 13:20
Windows clock() doesn't seem to return processor time [when you Sleep()]
#define WIN32_LEAN_AND_MEAN
#include <tchar.h>
#include <windows.h>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#if !defined(__cplusplus) && defined(_MSC_VER)
typedef enum { false, true } bool;
@hanji
hanji / min_and_max.cpp
Created January 1, 2012 08:55
simultaneous min and max of sequential container: a case of premature optimization/gratuitous pessimization.
#define WIN32_LEAN_AND_MEAN
#define NOMINMAX
#include <windows.h>
#include <io.h>
#include <cstdlib>
#include <ctime>
#include <iostream>
#include <limits>
#include <tuple>
#include <vector>
@hanji
hanji / csdntopk.cpp
Created January 6, 2012 06:22
find out passwords most frequently used by CSDN users
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
#include <unordered_map>
int main()
@hanji
hanji / zobrist.cpp
Created January 20, 2012 14:57
I wish C++ had reflection... typeid(T).name() is just weird.
#include <cstdint>
#include <cstdlib>
#include <ctime>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <iostream>
#include <typeinfo>
#include <vector>
#include <boost/random.hpp>
@hanji
hanji / sudo.js
Created September 8, 2012 07:55
WSH script to launch application with elevated privileges
(function(){
if (WScript.Arguments.Length !== 0){
var app = WScript.Arguments(0);
} else {
WScript.Echo('sudo <application> [<parameters>]');
WScript.Quit(1);
}
var sh = new ActiveXObject('Shell.Application');
@hanji
hanji / savechrome.cmd
Created September 8, 2012 22:44
this script will poll the temp folder and keep a copy of the chrome installer before it disappears
@echo off
setlocal enableextensions
set dest=%userprofile%\downloads
pushd %temp%
:loop
for /f "usebackq delims=;" %%i in (`dir /a /b /s *.msi *.exe ^| findstr /i ^"chrome^"`) do (
if not exist "%dest%\%%~nxi" xcopy "%%i" "%dest%\" >nul 2>&1
)
@hanji
hanji / init.el
Created September 9, 2012 18:08
updated config file for emacs 24
;;; init.el --- emacs configuration file
;; (C) Copyright 2009-2012 Ji Han
;; Last Updated: Mon, 10 Sep 2012 02:00:53
;; custom-set-variables and custom-set-faces
;; {{{
(custom-set-variables
;; custom-set-variables was added by Custom.
;; If you edit it by hand, you could mess it up, so be careful.
;; Your init file should contain only one such instance.
@hanji
hanji / .vimrc
Created September 9, 2012 19:30
vim configuration file
"vim configuration file
"(C) Copyright 2009-2012, Ji Han
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
set fileencodings=ucs-bom,utf-8,gbk,big5,euc-jp,euc-kr,default
set encoding=utf-8
language message en_US.utf-8
set langmenu=en_US.utf-8
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""