Skip to content

Instantly share code, notes, and snippets.

@cutewalker
cutewalker / web_import_chardet.py
Created October 26, 2012 02:28
use chardet example, from openerp
# -*- coding: utf-8 -*-
# https://github.com/buke/openerp-web-import-chardet/blob/master/web_import_chardet/controllers/__init__.py
##############################################################################
# web_import_chardet
# Auto Detect Import File Encoding & Remove BOM Header In UTF8 File.
# Copyright 2012 wangbuke <wangbuke@gmail.com>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
@cutewalker
cutewalker / QuickPhrase.mb
Created November 29, 2012 02:56
fcitx QuickPhrase.mb
# 颜文字欢呼
yhuanhu (/≥▽≤/)
yhuanhu ヾ(o◕∀◕)ノ
yhuanhu ✪ω✪
yhuanhu *★,°*\:.☆\( ̄▽ ̄)/$\:*.°★*
yhuanhu ヾ (o ° ω ° O ) ノ゙
yhuanhu ╰(*°▽°*)╯
yhuanhu (。◕ˇ∀ˇ◕)
yhuanhu o(*≧▽≦)ツ
yhuanhu ≖‿≖✧
@cutewalker
cutewalker / gist:4632380
Created January 25, 2013 06:55
where is the zen mode?
where?
data:text/html, <style type="text/css">.e{position:absolute;top:0;right:0;bottom:0;left:0;}</style><div class="e" id="editor"></div><script src="http://d1n0x3qji82z53.cloudfront.net/src-min-noconflict/ace.js" type="text/javascript" charset="utf-8"></script><script>var e=ace.edit("editor");e.setTheme("ace/theme/monokai");e.getSession().setMode("ace/mode/ruby");</script>
<!--
For other language: Instead of `ace/mode/ruby`, Use
Markdown -> `ace/mode/markdown`
Python -> `ace/mode/python`
C/C++ -> `ace/mode/c_cpp`
Javscript -> `ace/mode/javascript`
Java -> `ace/mode/java`
Scala- -> `ace/mode/scala`
Adjust the number of pre/post lines (-B and -A args) as needed:
tcpdump -n -S -s 0 -A 'tcp dst port 80' | grep -B3 -A10 "GET /url"
This lets you get the HTTP requests you want, on the box, without generating a huge PCAP file that you have to offload somewhere else.
Keep in mind, that the BPF filter is never exact, if there are a large number of packets flowing through any box, BPF can and will drop packets.
# redis-cli -p 6379
redis 127.0.0.1:6379> SET visits 1
OK
redis 127.0.0.1:6379> GET visits
"1"
redis 127.0.0.1:6379> INCR visits
(integer) 2
redis 127.0.0.1:6379> exit
@cutewalker
cutewalker / ping-ip-list.sh
Created June 18, 2014 13:53
ping ips in a list
#!/bin/bash
IP_LIST=("a" "b" "c")
for ip in ${IP_LIST[*]}; do
ping -c 6 $ip
echo " "
done
@cutewalker
cutewalker / ssh-to-private-ip
Created June 20, 2014 03:29
ssh-to-private-ip
http://unix.stackexchange.com/questions/87432/ssh-to-private-ip
ssh -f -N -R 12345:localhost:22 remote
# hg serve --webdir-conf hgweb.cfg -p port_num
[paths]
path=dirname
[web]
allow_archive = bz2 gz
push_ssl = false
allow_push = *
@cutewalker
cutewalker / magic_square.py
Created December 13, 2014 04:25
find all solutions of n-order magic square
# -*- coding: utf-8 -*-
"""
find all solutions of n-order magic square
"""
import itertools
class Solver(object):
def __init__(self, n, square=None, magic_sum=None):