Skip to content

Instantly share code, notes, and snippets.

😴
Moving stuff into GitHub!

Jindi Wu kymair

😴
Moving stuff into GitHub!
View GitHub Profile
View gist:ce30789bf5031b589e0fda39e01ce045
for file in *.html;do pandoc $file -f html -t plain -o ${file%.*}.md; done
@kymair
kymair / ubuntu-virtualbox.sh
Created Aug 22, 2014
Ubuntu in VirtualBox
View ubuntu-virtualbox.sh
# Configure APT
sudo sed -i '%s/cn.archive.ubuntu.com/mirror.bit.edu.cn/g' /etc/apt/sources.list
sudo apt-get update
sudo apt-get upgrade
sudo apt-get install build-essential
# Install VirtualBox addons
sudo mount -t auto /dev/cdrom /media/cdrom
cd /media/cdrom
sudo ./VBoxLinuxAdditions.run
View gist:cdb26b409fa7e385c820
/* Bit Wtiddling Hacks http://graphics.stanford.edu/~seander/bithacks.html#RoundUpPowerOf2
java.util.ArrayDeque - find the nearest power of two */
private void allocateElements(int numElements) {
int initialCapacity = MIN_INITIAL_CAPACITY;
// Find the best power of two to hold elements.
// Tests "<=" because arrays aren't kept full.
if (numElements >= initialCapacity) {
initialCapacity = numElements;
initialCapacity |= (initialCapacity >>> 1);
View gist:8574867
# build-essential in CentOS
sudo yum groupinstall 'Development Tools'
View cpu-bench.sh
#!/bin/bash
CONCURRENCY=8
TIME_START=`date`
for ((idx = 0; idx < $CONCURRENCY; idx++))
do
time echo "scale=5000; a(1)*4" | bc -l > /dev/null &
done
echo "$TIME_START Start"
@kymair
kymair / update-dns.py
Last active Jul 12, 2018
Python script to update Linode DNS
View update-dns.py
# Get Linode API python bindings from https://github.com/tjfontaine/linode-python
#!/usr/bin/python
from linode import api
instance = api.Api(key='abcdefg')
for domain in instance.domain_list():
if domain['TYPE'] == 'master':
print "Updating %s (%i)..." % (domain['DOMAIN'], domain['DOMAINID'])
View gist:4361955
# Create a temp big file on server
kymair:wwwroot/ $ dd if=/dev/zero of=file.zip bs=1M count=100
# wget that file from client, two connections at the same time
~ wget kymair.com/file.zip > /dev/null 2&>1 &
[1] 79229
~ wget kymair.com/file.zip > /dev/null 2&>1 &
[2] 79234
# Client netstat result
@kymair
kymair / mailbox_cleaner.rb
Created Dec 18, 2012
Handy Ruby script to empty IMAP mailbox
View mailbox_cleaner.rb
#!/usr/bin/env ruby
MAILBOXES = ['INBOX', 'Deleted Items']
SERVER = 'server'
USERNAME = 'username'
PASSWORD = 'password'
require 'net/imap'
imap = Net::IMAP.new(SERVER)
@kymair
kymair / file1.clj
Created Jul 31, 2012
Read and write file in Clojure
View file1.clj
(use '[clojure.string :only [split]])
(require '[clojure.java.io :as io])
(def format-str "%1$-255s%2$09d%3$-255s%4$-1000s%5$-1s")
(defn format-line
[line]
(let [[v1 v2 v3 v4 v5] (split line #",")]
(format format-str v1 (read-string v2) v3 v4 v5)))
@kymair
kymair / ldapper.clj
Last active Oct 7, 2015
Update LDAP password
View ldapper.clj
(ns ldapper.core
(:require [clj-ldap.client :as ldap]
[clj-message-digest.core :as cdigest])
(:gen-class))
(def server (ldap/connect {:host "server:3997" :bind-dn "cn=Directory Manager" :password "password"}))
(def base-dn "ou=people,o=kymair.com")
(defn- hash-password
You can’t perform that action at this time.