Skip to content

Instantly share code, notes, and snippets.

@quark-zju
quark-zju / gdb-trace.py
Last active November 5, 2022 12:21
Trace all function calls using gdb
View gdb-trace.py
#!/usr/bin/env python
try:
import gdb
inside_gdb = True
except ImportError:
inside_gdb = False
if inside_gdb:
@quark-zju
quark-zju / list_cn_ip.rb
Created April 27, 2012 05:11
List allocated china ip addresses
View list_cn_ip.rb
#!/usr/bin/env ruby
# List latest china IPv4 list
require 'open-uri'
(ARGF.path == '-' ? open('http://ftp.apnic.net/apnic/stats/apnic/delegated-apnic-latest') : ARGF).lines.each do |l|
next if !l.include?('ipv4') || l.include?('*')
cc, type, start, value = l.split('|')[1, 4]
@quark-zju
quark-zju / Hello.java
Last active July 15, 2020 18:14
Java hello world in jar with Makefile
View Hello.java
public class Hello {
public static void main(String args[]) {
System.out.println("hello world");
}
}
View Cargo.toml
[package]
name = "pathmatcher"
version = "0.1.0"
edition = "2018"
[lib]
path = "lib.rs"
[dependencies]
bitflags = "1.0"
@quark-zju
quark-zju / lodash.hpp
Last active February 5, 2020 02:14
Little C++ header inspired by Ruby and Lo-dash
View lodash.hpp
// compile with -std=c++1y
#include <algorithm>
#include <functional>
#include <iterator>
#include <vector>
namespace LoDash {
using std::begin;
@quark-zju
quark-zju / sftp-changes.py
Created April 17, 2019 16:10
A naive incremental sync script via sftp
View sftp-changes.py
#!/usr/bin/env python
"""A naive incremental sync script via sftp
When do you want to use this?
- want a non-lazy local file system (not fuse/sshfs)
- sftp is configured easier to use than ssh (rsync or git)
This script is very simple and does not handle complex cases. Use rsync to:
- set up an initial mirror
@quark-zju
quark-zju / backtrace.c
Created April 5, 2014 14:11
(Linux) Print backtrace
View backtrace.c
// Link with -rdynamic
#include <execinfo.h>
#include <assert.h>
#include <stdio.h>
#include <assert.h>
#include <stdlib.h>
void bt() {
const size_t size = 100;
@quark-zju
quark-zju / qingcloud-control.rb
Created June 2, 2015 14:38
Poor man's qingcloud single instance management script
View qingcloud-control.rb
#!/usr/bin/env ruby
# qingcloud-control
#
# Poor man's qingcloud single instance management script. You may find this script useful, if you:
# - are an individual qingcloud user. do not have a lot of instances (assuming only one)
# - do not need to run instance 7x24. instances are powered off most of the time
# - do not use advanced networks. no routers, no private networks. just an instance with default network and an eip attached
# - want to save money
# - use ssh to login, have following lines in ~/.ssh/config:
@quark-zju
quark-zju / mssh.rb
Last active December 8, 2016 19:09
Use tiled view correctly
View mssh.rb
#!/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 / tango-colors.css.scss
Created April 17, 2014 01:49
Tango colors (SCSS)
View tango-colors.css.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