Skip to content

Instantly share code, notes, and snippets.

@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 / 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 / mydft.py
Last active April 21, 2023 16:19
Intuitive impementation of discrete Fourier transform (and inverse DFT) in Python (without numpy)
#!/usr/bin/env python3
import math
# >> Discrete Fourier transform for sampled signals
# x [in]: sampled signals, a list of magnitudes (real numbers)
# yr [out]: real parts of the sinusoids
# yi [out]: imaginary parts of the sinusoids
def dft(x):
N, yr, yi = len(x), [], []
@dannvix
dannvix / intercept-https-with-python-mitmproxy.md
Last active February 16, 2023 02:43
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 / yyets-subdl.py
Last active November 6, 2022 09:24
YYeTs (人人影视) 雙語字幕下載器
# Moved to https://github.com/dannvix/yyets-subdl
import webbrowser
webbrowser.open('https://github.com/dannvix/yyets-subdl')
/* 引入 Win32 API 中的 User32.DLL
* 需要加上 using System.Runtime.InteropServices;
*/
[DllImport("user32.dll")]
public static extern Boolean GetWindowRect(IntPtr hWnd, ref Rectangle bounds);
public void CaptureWindow () {
/* 取得目標視窗的 Handle
* 需要加上 using System.Diagnostics;
*/
@dannvix
dannvix / django-JsonResponse.py
Last active March 31, 2022 06:44
Custom Django JsonResponse which supports datetime.datetime serialization
# project/forum/views.py
import json
from datetime import datetime
from django.http import HttpResponse
from django.shortcuts import get_object_or_404
from django.forms.models import model_to_dict
from forum.models import Post
@dannvix
dannvix / electron-main.js
Created June 24, 2015 15:44
Create Electron's BrowserWindow with dynamic HTML content
// main.js for Electron
var app = require("app"),
BrowserWindow = require("browser-window");
app.on("window-all-closed", function() {
app.quit();
})
var mainWindow = null;
app.on("ready", function() {
@dannvix
dannvix / c99-heap.c
Created October 8, 2015 14:58
Simple std::priority_queue-like container implemented in C99, without error handling and thread-safety
/*
* c99-heap.c
* - Description: Simple std::priority_queue-like container implemented in C99, without error handling and thread-safety
* - Author: Shao-Chung Chen
* - License: CC0
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdbool.h>
@dannvix
dannvix / www-proxy.c
Created January 30, 2013 06:47
very simple HTTP proxy server written by Steve Shipway
/* www-proxy.c Copyright Imperial Business Systems 1995
Proxy http server.
Written by Steve Shipway (steve@cheshire.demon.co.uk,steve@imperial.co.uk)
in the space of 2 hours. It took a further 1 hour to remove the last
bug. And 2 hours to persuade myself to stop playing with Netscape after it
was working.
Command line args:
-d : debug mode. Use port 8000 instead, dont background, status msgs
-l logfile : logfile to use