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
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
#=====================================================
@dalang
dalang / get_full_teamname.pl
Created May 11, 2013 17:15
get nba full teamname from an html file, parse it and print in "key(abb teamname) : value(full teamname)" format get nba teamname from html code from espn.com
#!/usr/bin/perl
open(IFILE, "<fullteamname.html");
open(FILE, ">_ftn.txt");
while(<IFILE>) {
chomp();
if ($_ =~ /<h4>(\w+?)<\/h4>/) {
$sec = $1;
print $sec;
@dalang
dalang / copy.pl
Created May 11, 2013 17:07
copy data from one file to another file line for line
#!/usr/bin/perl
open(IFILE, "<index.html");
open(FILE, ">_tmpfile.txt");
while(<IFILE>) {
chomp();
syswrite(FILE, $_);
syswrite(FILE, "\n");
}