Skip to content

Instantly share code, notes, and snippets.

View ryaninhust's full-sized avatar

Bowen Yuan ryaninhust

  • NYC
  • 19:14 (UTC -04:00)
View GitHub Profile
@ryaninhust
ryaninhust / .gdbinit
Created March 6, 2013 02:05
GDB 配置
set print pretty on
set print object on
set print static-members on
set print vtbl on
set print demangle on
set demangle-style gnu-v3
set print sevenbit-strings off
python
import sys
sys.path.insert(0, '/home/ryanhust/ryanlib/python')
在macbook pro 4核上的测试结果,python自带的map表现比起ipython 的map,list comprehensions都要好。但是有优化的multi_mcpi还是不错。
$ ipcluster start --n=4
print mcpi(100000000)
#print multi_mcpi_by_map(dview, 100000000) # 传递太耗时
#print multi_mcpi_by_list_comp(dview, 100000000)
#print multi_mcpi(dview, 100000000)
$ time py multi_mcpi.py
importing random from random on engine(s)
@ryaninhust
ryaninhust / gist:5434022
Last active December 16, 2015 12:19
ryan's vimrc
set mouse=a
set nu
runtime! debian.vim
syntax on
set background=dark
set cursorcolumn
set cursorline
filetype plugin indent on
filetype off
" format and user interface
@ryaninhust
ryaninhust / gist:5476115
Created April 28, 2013 06:36
Charging Ipad on linux, python script
#!/usr/bin/python
import usb.core
import usb.util
import usb.backend.libusb10
import sys, getopt
opts = getopt.getopt(sys.argv[1:],'',['off'])
off = 'off' in opts[1]
@ryaninhust
ryaninhust / gist:5582111
Created May 15, 2013 06:59
Extract data from LIBSVM format
/* strtok example */
#include <stdio.h>
#include <cstring>
#include <string>
#include <vector>
using namespace std;
int main ()
{
char str[] ="1 1:1 2:2 3:3";
char * pch;
@ryaninhust
ryaninhust / inversion.py
Last active December 17, 2015 10:49
Find inversions in Array
def merge_array(l_array, r_array):
merged_array = []
i, j = 0, 0
local_count = 0
while(i < len(l_array) and j < len(r_array)):
if l_array[i] > r_array[j]:
merged_array.append(r_array[j])
local_count += len(l_array) - i
j += 1
else:
@ryaninhust
ryaninhust / Class Puzzle
Created November 13, 2013 15:36
Show Puzzle about Python Class Attributes and Instance Attributes
>>> class Case(object):
... a = []
... def show_attribute(self):
... print self.a
>>> Case.a
[]
>>> case = Case()
>>> case.a
[]
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title></title>
<style>
.config{width:250px;margin: 40px auto;}
.grid{display:none;border-collapse:collapse; margin:30px auto 0 auto;}
.grid td{width:50px; height:50px; text-align:center; vertical-align:middle;}
.choice{display:inline-block;width:100px;}
from copy import deepcopy
RED = 1 # max
BLACK = 2 # min
class Board(object):
def __init__(self, width=5, height=4, win_len=4, depth=2):
self.width = width