Skip to content

Instantly share code, notes, and snippets.

@arsane
arsane / mastermind.cpp
Created March 22, 2015 06:08
mastermind.cpp in c++11
#include <algorithm>
#include <iostream>
#include <map>
using namespace std;
/**
* @brief repeat helper.
*/
template <typename F>
@arsane
arsane / solution1.cpp
Created March 19, 2015 15:25
mastermind
string colors("BGR"), comb(4, '.'), l(comb), guess;
typedef map<int,int> M;
struct Color {
Color( M& cm, M& gm, int& color )
: cm_(cm), gm_(gm), color_(color=0) { }
void operator()( char c )
{ color_ += min( cm_[c], gm_[c] ); }
M &cm_, &gm_;
@arsane
arsane / swift.md
Created March 1, 2015 09:56
openstack swift notes.

Requirements

  • Ubuntu 12.04
  • OpenStack havana release
  • python-swiftclient Swifit CLI
  • cURL
  • Swift tools such as Swift-Recon, Swift-Informant, and Swift-Dispersion
  • A StatsD server. https://github.com/etsy/statsd
@arsane
arsane / monitorcard.py
Created February 17, 2015 10:07
Detect dynamic smart card insertion and removal.
from smartcard.System import readers
from smartcard.CardType import AnyCardType
from smartcard.CardRequest import CardRequest
from smartcard.CardConnection import CardConnection
from smartcard.util import toHexString, toBytes
from smartcard.CardMonitoring import CardMonitor, CardObserver
from smartcard.util import *
from time import sleep
def check_reader():
// ==UserScript==
// @name ganster
// @namespace [email protected]
// @include http://www.sexgangsters.com/*
// @version 1
// @grant none
// ==/UserScript==
var api_call = function(api_method, api_args, api_callback) {
return function() {
@arsane
arsane / remove_duplicates.py
Created August 25, 2014 02:36
remove files with same content under same folder.
import os, sys
import hashlib
def file_digest(f):
m = hashlib.md5()
m.update(file(f).read())
return m.hexdigest()
def remove_duplicates(dir):
# size, list of files.
@arsane
arsane / chinese-count.py
Created August 24, 2014 13:36
count chinese characters.
#!/usr/bin/python3
import sys
def MyCount(string):
tmpStr = ""
for c in string:
if ord(c)>=255 and (c not in ",。!¥()《》【】『』、?~·:“”‘’;"): tmpStr += c
return len(tmpStr)
if __name__=="__main__":
@arsane
arsane / hgfolderdiff.py
Last active August 29, 2015 14:05
export mercurial revision changes in folders.
# This script is used to export changes between two commits
# into two folders for people don't have hg to review code.
#
# Usage:
# python hgfolderdiff.py rev1 rev2 diffs.zip
#
# export change files in two revisions into two directories,
# and then archive to zip file.
#
import os, subprocess, sys
@arsane
arsane / callgraph.py
Created December 3, 2013 04:14
retrieve the call graph from elf binary.
#!/usr/bin/python
# powerpc-gekko-objdump -d example.elf | python cg.py | dot -Tpng > cg.png && eog cg.png
import re, sys
f_re = re.compile('^[0-9a-f]* <([a-zA-Z0-9_]*)>:$')
c_re = re.compile('\tbl *[0-9a-f]* <([a-zA-Z0-9_]*)>')
_blacklist = set(['sys_init', 'SYS_ResetSystem', 'puts', 'getButtons',
@arsane
arsane / rsa.py
Created November 25, 2013 06:37
use python to do rsa calculation.
# Simple python script to check each steps of RSA calculation.
# Keys.
n = 0xAA9DE43925350CD9C0F1F98017FFD882BCFE524122212E764C6D529989B4192169B30559BDFA0F6F3037C3FDF54E18D2A36028E1940BEF14A472D50814A1089861B541491E2CA61652012FBC9E381CD744860F22EB4DD4274AF5C87EF5D05BD5040D8BA550A0FA59C1AFF7B354DF565B531B4ECF4DE731F5998F651BE25146E7
ns = 'AA9DE43925350CD9C0F1F98017FFD882BCFE524122212E764C6D529989B4192169B30559BDFA0F6F3037C3FDF54E18D2A36028E1940BEF14A472D50814A1089861B541491E2CA61652012FBC9E381CD744860F22EB4DD4274AF5C87EF5D05BD5040D8BA550A0FA59C1AFF7B354DF565B531B4ECF4DE731F5998F651BE25146E7'
e = 0xEDBE77C1
p = 0xE091BB42189DEA18CF8EE01A2407A6F0DF154C026948CBBE2857584885D60C08E1CD91FB47C35D07E337FF162201BEF10E6D9CBAE975AA086A0E6C6ABD85DE65
q = 0xC27F0DB3D6B798AD36340B56A402467476433A9034953DE611062ECEE87E2A2A46EEFA4900DE013B13191CD0FC84ABFB4CAE01AD22E6F19D4C97AB76CA02455B