Skip to content

Instantly share code, notes, and snippets.

@dannvix
dannvix / decorator.rb
Created March 2, 2013 12:20
Python style decorators for Ruby. Copied from github://michaelfairley/method_decorators
module MethodDecorators
class Decorator
@@current_decorators = []
def self.current_decorators
decs = @@current_decorators
@@current_decorators = []
decs
end
@dannvix
dannvix / i-dont-sponsor-facebook.user.js
Last active December 15, 2015 07:59
Userscript for automatically hiding "sponsored posts" (i.e. advertisements) on Facebook. Originally published on http://userscripts.org/scripts/show/160461 in Feb 2013
// ==UserScript==
// @name Facebook Sponsored Posts Cleaner
// @description Automatically Hides Sponsored Posts (Ads) in Facebook Stream
// @namespace http://facebook.example.org
// @author Shao-Chung Chen
// @license MIT (http://opensource.org/licenses/MIT)
// @version 1.3
// @include http://*.facebook.com/*
// @include https://*.facebook.com/*
//
@dannvix
dannvix / nginx-non-transparent-ssl-proxy.md
Last active October 16, 2023 19:07
Guide to set up nginx as non-transparent SSL proxy, which subsitutes strings in the server responses

Use nginx as Non-Transparent SSL Proxy

Introduction

Many mobile apps have back-end API servers. They usually rely on the API replies to determine whether certain information is supposed to be shown. If the API responses could be manipulated on the fly, we may easily fool an unmodified app to expose some private data.

This manual guides you to set up nginx as non-transparent SSL proxy, which just subsitutes strings in the server responses (i.e. man-in-the-middle attack ourself). For both server-side (their API servers) and client-side (your device), the whole process is almost transparent.

@dannvix
dannvix / intercept-https-with-python-mitmproxy.md
Last active March 6, 2025 01:41
Intercept and manipulate HTTPs traffic with Python and mitmproxy

Intercepts HTTPs Traffic with Python & mitmproxy

Warning

This Gist is created in 2014, and it's highliy outdated now, according to one of mitmproxy's manjor contributor (check his comment below). Thanks for letting us know, @mhils!

Introduction

Modern applications usually make use of back-end API servers to provide their services. With a non-transparent HTTPs proxy, which intercepts the communication between clients and servers (aka the man-in-the-middle scheme), you can easily manipulate both API requests and responses.

@dannvix
dannvix / lat-lng-to-addr.py
Last active December 15, 2015 17:39
convert latitude & longitude to formatted address with Google Maps API
#!/usr/bin/env python
# -*- encoding: utf-8 -*-
import sys, traceback
import json, urllib2
def latlng_to_addr (lat, lng):
# convert given latitude & longitude to formatted address with Google Maps API
# ref: http://techslides.com/convert-latitude-and-longitude-to-a-street-address/
maps_api_url = 'http://maps.googleapis.com/maps/api/geocode/json?latlng=%s,%s&sensor=false' % (lat, lng)
try:
@dannvix
dannvix / lat-lng-to-addr.rb
Created April 3, 2013 03:32
convert latitude & longitude with Geocoder (Google Maps API)
#!/usr/bin/env ruby
require "geocoder"
def latlng_to_addr (lat, lng)
query_result = Geocoder.search("#{lat},#{lng}")
return query_result.first.formatted_address
end
if ARGV.length < 2
puts "usage: ./#{$0} <latitude> <longitude>"
@dannvix
dannvix / SubtitleParser.coffee
Last active December 15, 2015 21:19
very simple parser for 《蟲族之心》subtitles in CoffeeScript
#!/usr/bin/env coffee
class SubtitleParser
LINE_PATTERN = ///
subtitle #line prefix
\s+
(\d+) # timestamp
\s+
(\d+) # duration
\s+
@dannvix
dannvix / gen-piles.rb
Created April 12, 2013 16:42
for P piles with N items, generate all possible combinations without redundant
# for P piles with N items, generate all possible combinations without redundant
# e.g. for piles(5, 3) -> [(5,0,0), (4,1,0), (3,2,0), (3,1,1), (2,2,1)]
def make_piles (num, pile, piles=[], c=Array.new(pile, 0), idx=0)
if num == 0
piles.push(c.clone)
else
top = (c[idx-1] != 0) ? ((c[idx-1] > num) ? num : c[idx-1]) : (num)
top.downto(1).each do |i|
c[idx] = i
make_piles(num-i, pile, piles, c, idx+1)
@dannvix
dannvix / EchoServer.java
Created April 15, 2013 02:55
simple multithreading TCP echo server in (ugly) Java
import java.io.*;
import java.net.*;
import java.lang.Thread;
public class EchoServer {
public static void main (String[] args) {
try {
ServerSocket server = new ServerSocket(5566);
while (true) {
Socket client = server.accept();
@dannvix
dannvix / OSDC-2013-irc-logs.txt
Created April 20, 2013 15:45
#osdc.tw logs for OSDC 2013 (Apr 19 – 20)
--- Log opened Thu Apr 18 14:41:31 2013
14:44 < dannvix> hello world!
15:45 < hcchien> just saw the picture that ingy got Taiwan beer!
20:12 -!- chihchun is now known as zz_chihchun
21:57 < clkao> miyagawa: muchomucho++
21:58 < clkao> grr missing osdc!
22:08 < hcchien> miyagawa: ping
23:17 < hcchien> btw, we will have the hackathron on Sunday.
23:17 < lunastorm> woot
23:17 < lunastorm> where