Skip to content

Instantly share code, notes, and snippets.

@quark-zju
quark-zju / winlist-client.rb
Last active Aug 29, 2015
Win32 TCP service to provide windows titles and their flashing status.
View winlist-client.rb
#!/usr/bin/env ruby
# Example ruby client of winlist-server.
HOST = '172.22.22.1'
PORT = 4015
require 'socket'
require 'timeout'
@quark-zju
quark-zju / phabricator-gerrit-link.user.js
Created May 4, 2014
User script: Make Gerrit's "Change-Id" clickable from Phabricator Diffusion
View phabricator-gerrit-link.user.js
@quark-zju
quark-zju / memory-limit.rb
Last active Aug 29, 2015
Handy memory limit script
View memory-limit.rb
#!/usr/bin/env ruby
# For Linux only
# Limit: 2.5G, change it if needed
GIGA = 1024 ** 3
MEMORY_LIMIT = GIGA * 5 / 2
CG_DIR = "/sys/fs/cgroup/memory/lm.#{MEMORY_LIMIT}"
if ARGV.any?{|s|s.start_with? '-h'}
@quark-zju
quark-zju / callbacks.coffee
Created Jun 2, 2014
Simple in browser async callbacks
View callbacks.coffee
# Original Author: David Morrow
# https://github.com/dperrymorrow/callbacks.js
# MIT license
#
# Modified:
# - Rename method names. For example, remove `Callback`
# - Fix `remove`
# - Remove `instance`, change `method` from string to real method
# - Callbacks.add = Callbacks.get().add
@quark-zju
quark-zju / find-server.rb
Created Jul 9, 2014
Find the best server (lowest ping loss and latency) from a list of servers
View find-server.rb
#!/usr/bin/env ruby
require 'thread_safe'
require 'resolv'
exit 1 if Process.uid != 0
SERVERS = %w[
site-g1.example.com
site-g2.example.com
@quark-zju
quark-zju / quick-tc.rb
Created Jul 9, 2014
Quick & naive upload traffic limit
View quick-tc.rb
#!/usr/bin/env ruby
# quick egress traffic limit for linux
# Usage: $0 dev kbps
MIN_RATE = 512
devs = []
rate = 0
dev_names = Dir['/sys/devices/**/net/*'].map{|x|File.basename(x)}
@quark-zju
quark-zju / iptables_save.c
Last active Aug 29, 2015
Python ext for iptables-save
View iptables_save.c
#include <Python.h>
#include <libiptc/libiptc.h>
#include <xtables.h>
#include <stdio.h>
#include <netdb.h>
#include <string.h>
#define buffer_printf(...) {\
char temp_buf[1024];\
@quark-zju
quark-zju / create_machine.sh
Last active Aug 29, 2015 — forked from AVGP/create_machine.sh
Script to create a user-mode linux machine (tested under Debian 7)
View create_machine.sh
#!/bin/sh
### functions
f() { echo "Failed."; exit; }
check_packages()
{
hash linux || apt-get install user-mode-linux || f
hash debootstrap || apt-get install debootstrap || f
@quark-zju
quark-zju / git-pushf
Created Dec 1, 2014
Quick & dirty way to sync git to remote
View git-pushf
#!/usr/bin/env ruby
# Find git root
while !File.exists?('.git/config')
Dir.chdir('..')
raise 'git root not found' if Dir.pwd == '/'
end
args = ARGV
View copy-paste.sh
copy () {
cat "$@" 2> /dev/null | xsel -b
local _path
for _path in "$@"
do
if [ "${_path[1]}" = '/' ]
then
echo "${_path}"
else
echo "${PWD}/${_path}"