Skip to content

Instantly share code, notes, and snippets.

View kymair's full-sized avatar

Karl Popper kymair

View GitHub Profile
@kymair
kymair / update-dns.py
Last active July 12, 2018 13:30
Python script to update Linode DNS
# 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'])
for file in *.html;do pandoc $file -f html -t plain -o ${file%.*}.md; done
@kymair
kymair / gist:8574867
Created January 23, 2014 08:22
Shell Tips
# build-essential in CentOS
sudo yum groupinstall 'Development Tools'
#!/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"
# 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 December 18, 2012 09:07
Handy Ruby script to empty IMAP mailbox
#!/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 July 31, 2012 10:07
Read and write file in Clojure
(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 October 7, 2015 09:08
Update LDAP password
(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
@kymair
kymair / ubuntu-virtualbox.sh
Created August 22, 2014 13:30
Ubuntu in VirtualBox
# 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
@kymair
kymair / gist:cdb26b409fa7e385c820
Created June 24, 2014 01:27
Dive into Java Source
/* 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);