Skip to content

Instantly share code, notes, and snippets.

View dalang's full-sized avatar

大浪 dalang

  • Dada Group
  • Shanghai
View GitHub Profile
@dalang
dalang / ko_math_whiz
Created May 30, 2018 06:40
If the big number 5555…5555 ( a total of 2000 digits)is divided by 84, what's the remainder?
int('5' * 2000) % 84
@dalang
dalang / docker-compose.yml  
Created May 27, 2018 07:11
docker-compose for clair and clairctl
version: '2.1'
services:
postgres:
container_name: clair_postgres
image: postgres:latest
restart: unless-stopped
environment:
POSTGRES_PASSWORD: password
clair:
@dalang
dalang / nth_monisen_number.py 
Created May 25, 2018 04:49
find the n-th Monisen number. A number M is a Monisen number if M=2**P-1 and both M and P are prime numbers. For example, if P=5, M=2**P-1=31, 5 and 31 are both prime numbers, so 31 is a Monisen number.
import math
PRIME_NUMBERS = []
def is_monisen_number(value):
log2 = int(math.log2(value + 1))
return 2**log2 == value + 1 and log2 in PRIME_NUMBERS
@dalang
dalang / yanghui_triangle.py
Created May 11, 2015 17:07
print yanghui triangle
def yanghui_triangle():
def safe_get_value(l, index):
length = len(l)
return 0<= index < length and l[index] or 0
tmp = [1]
while True:
yield tmp
length = len(tmp)
new = []
@dalang
dalang / retry_decorator.py
Created April 21, 2015 05:30
decorator for retrying function in specific times
def retry(attempt, raise_on_fail=False):
def decorator(func):
def wrapper(*args, **kw):
att = 0
last_except = None
while att < attempt:
try:
return func(*args, **kw)
except Exception as e:
att += 1
grandparent = self.class.superclass.superclass
meth = grandparent.instance_method(:the_method)
meth.bind(self).call
#
# Author:: BinaryBabel OSS (<projects@binarybabel.org>)
# Homepage:: http://www.binarybabel.org
# License:: MIT
#
# For bugs, docs, updates:
#
# http://code.binbab.org
#
# Copyright 2013 sha1(OWNER) = df334a7237f10846a0ca302bd323e35ee1463931
@dalang
dalang / README.md
Last active December 22, 2015 02:19
oh-my-zsh razor plugin

#oh-my-zsh razor plugin Enable Razor from puppetlabs capability of command autocomplete

Ensure you have installed oh-my-zsh ###How to use this razor plugin:

  1. mkdir a new folder named razor in your oh-my-zsh plugin folder: ~/.oh-my-zsh/plugins/razor
  2. put this file in ~/.oh-my-zsh/plugins/razor
  3. config your ~/.zshrc to enable razor plugin: add razor in the bracket of the line starts with plugins=(
  4. Try type razor in terminal and test command autocomplete with tab
@dalang
dalang / raw.rb
Created July 24, 2013 17:23
test dynamically add instance_variables or class_variables to class.
class Mine
@xxx = 1
attr_accessor :some_var
def intialize
@some_var = true
end
class << self
def my_number num
@dalang
dalang / parse_csv.sh
Created July 18, 2013 11:47
bash script to get data from csv file and run command with the parsed info
#!/bin/bash
#=====================================================
#== USAGE: HW_bmc_conf.sh [csvFilename] <SerialNumber>
#== Return:
#== 0 -- normal
#== 1 -- Args error
#== 2 -- imana configuration file is not exist
#== 3 -- The Server with given serialnumber is NOT in csv File
#=====================================================