Skip to content

Instantly share code, notes, and snippets.

Guoxing Dong dalang

Block or report user

Report or block dalang

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
@dalang
dalang / ko_math_whiz
Created May 30, 2018
If the big number 5555…5555 ( a total of 2000 digits)is divided by 84, what's the remainder?
View ko_math_whiz
int('5' * 2000) % 84
@dalang
dalang / docker-compose.yml  
Created May 27, 2018
docker-compose for clair and clairctl
View docker-compose.yml  
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
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.
View nth_monisen_number.py 
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
print yanghui triangle
View yanghui_triangle.py
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 Apr 21, 2015
decorator for retrying function in specific times
View retry_decorator.py
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
View double_super.rb
grandparent = self.class.superclass.superclass
meth = grandparent.instance_method(:the_method)
meth.bind(self).call
View vagrant-wrapper.rb
#
# 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 Dec 22, 2015
oh-my-zsh razor plugin
View README.md

#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 Jul 24, 2013
test dynamically add instance_variables or class_variables to class.
View raw.rb
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 Jul 18, 2013
bash script to get data from csv file and run command with the parsed info
View parse_csv.sh
#!/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
#=====================================================
You can’t perform that action at this time.