Skip to content

Instantly share code, notes, and snippets.

@quark-zju
quark-zju / mssh.rb
Last active December 8, 2016 19:09
Use tiled view correctly
#!/usr/bin/env ruby
require 'digest'
hosts = ARGV.to_a
hosts = $<.each_line.map(&:chomp) if hosts.empty?
hosts.uniq!
def system! *args
raise "Cannot exec #{args}" unless system(*args.flatten)
@quark-zju
quark-zju / iptables_save.c
Last active August 29, 2015 14:05
Python ext for iptables-save
#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 / lodash.hpp
Last active February 5, 2020 02:14
Little C++ header inspired by Ruby and Lo-dash
// compile with -std=c++1y
#include <algorithm>
#include <functional>
#include <iterator>
#include <vector>
namespace LoDash {
using std::begin;
@quark-zju
quark-zju / find-server.rb
Created July 9, 2014 04:30
Find the best server (lowest ping loss and latency) from a list of servers
#!/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 July 9, 2014 04:23
Quick & naive upload traffic limit
#!/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 / memory-limit.rb
Last active August 29, 2015 14:02
Handy memory limit script
#!/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 June 2, 2014 03:02
Simple in browser async callbacks
# 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 / phabricator-gerrit-link.user.js
Created May 4, 2014 07:57
User script: Make Gerrit's "Change-Id" clickable from Phabricator Diffusion
@quark-zju
quark-zju / winlist-client.rb
Last active August 29, 2015 14:00
Win32 TCP service to provide windows titles and their flashing status.
#!/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 / tango-colors.css.scss
Created April 17, 2014 01:49
Tango colors (SCSS)
// Highlight Shadow
// Aluminium #eeeeec #d3d7cf #babdb6
// Butter #fce94f #edd400 #c4a000
// Chameleon #8ae234 #73d216 #4e9a06
// Orange #fcaf3e #f57900 #ce5c00
// Chocolate #e9b96e #c17d11 #8f5902
// Sky Blue #729fcf #3465a4 #204a87
// Plum #ad7fa8 #75507b #5c3566
// Slate #888a85 #555753 #2e3436
// Scarlet Red #ef2929 #cc0000 #a40000