Skip to content

Instantly share code, notes, and snippets.

@quark-zju
quark-zju / backtrace.c
Created April 5, 2014 14:11
(Linux) Print backtrace
// 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 / lock.bat
Created July 5, 2013 08:12
Lock Windows.
rem Enable Win+L, Lock Windows, Disable Win+L.
rem Useful as a workaround to disable Win+L while being able to lock.
rem This makes sence if you are using Win+L for other purpose, for example, use Win+L inside a virtual Linux system.
rem Run this as Administrator. If it is annoying, try UAC Trust shortcut from www.itknowledge24.com
reg add HKCU\Software\Microsoft\Windows\CurrentVersion\Policies\System /v DisableLockWorkstation /t REG_DWORD /d 0 /f
rundll32 user32.dll,LockWorkStation
reg add HKCU\Software\Microsoft\Windows\CurrentVersion\Policies\System /v DisableLockWorkstation /t REG_DWORD /d 1 /f
@quark-zju
quark-zju / Hello.java
Last active July 15, 2020 18:14
Java hello world in jar with Makefile
public class Hello {
public static void main(String args[]) {
System.out.println("hello world");
}
}
@quark-zju
quark-zju / .gitignore
Created November 23, 2012 19:29
Linux tutorial slide for MSTC.ZJU
*.html
@quark-zju
quark-zju / spec_fetcher.rb
Created October 22, 2012 13:51
Patched ruby-1.9.3-p{194,286}/lib/ruby/1.9.1/rubygems/spec_fetcher.rb to prefer local cached version even it's a little out-dated. This makes gem / bundle command a lot faster under slow Internet connection.
require 'rubygems/remote_fetcher'
require 'rubygems/user_interaction'
require 'rubygems/errors'
require 'rubygems/text'
##
# SpecFetcher handles metadata updates from remote gem repositories.
class Gem::SpecFetcher
@quark-zju
quark-zju / ipv4_inv.cc
Created August 31, 2012 11:13
Invert IPv4 address list: Given a IPv4 address (with netmasks) list A, output another list B, s.t. A & B = [], A + B = Internet - Private Addresses
#include <cstdio>
#include <cinttypes>
#include <stdexcept>
#include <set>
union IPv4Addr {
struct {
uint32_t x;
uint8_t prefix;
};
@quark-zju
quark-zju / list_cn_ip.rb
Created April 27, 2012 05:11
List allocated china ip addresses
#!/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 / colorful_logger.rb
Created April 17, 2012 10:42
A colorful Logger for ruby
require 'term/ansicolor'
require 'logger'
class String
include Term::ANSIColor
end
class ColorfulLogger < Logger
def initialize(logdev, shift_age = 0, shift_size = 1048576)