Skip to content

Instantly share code, notes, and snippets.

View jim3ma's full-sized avatar
🎯
Focusing

Jim Ma jim3ma

🎯
Focusing
View GitHub Profile
@jim3ma
jim3ma / blog-webpack-2.md
Created January 16, 2018 12:35 — forked from xjamundx/blog-webpack-2.md
From Require.js to Webpack - Part 2 (the how)

This is the follow up to a post I wrote recently called From Require.js to Webpack - Party 1 (the why) which was published in my personal blog.

In that post I talked about 3 main reasons for moving from require.js to webpack:

  1. Common JS support
  2. NPM support
  3. a healthy loader/plugin ecosystem.

Here I'll instead talk about some of the technical challenges that we faced during the migration. Despite the clear benefits in developer experience (DX) the setup was fairly difficult and I'd like to cover some of the challanges we faced to make the transition a bit easier.

@jim3ma
jim3ma / gfw_and_cannon_traceroute.py
Created August 11, 2016 07:37
A Tool for Tracerouting the GC and GFW
#!/usr/bin/env python
import time
import threading
from scapy.all import *
import sys
import socket
maxhop = 25
@jim3ma
jim3ma / recvfd.c
Last active August 21, 2018 06:26 — forked from kokjo/sendfd.c
Send a file descriptor over an abstract unix domain socket
// compile with: gcc -static -o recvfd recvfd.c
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/un.h>
#include <strings.h>
/**
* Receives file descriptor using given socket
*
* @param socket to be used for fd recepion
@jim3ma
jim3ma / recvfd.c
Created August 22, 2018 14:53
Send a file descriptor over an abstract unix domain socket
#include <stdlib.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/un.h>
#include <stdio.h>
#include <strings.h>
#include <errno.h>
#define NAME ".socket"
@jim3ma
jim3ma / gist:3d0ec24c2ecc00db62612596f8ccd6a4
Created July 31, 2019 03:57 — forked from anonymous/gist:5543343
Golang major minor device numbers
package main
import (
"flag"
"fmt"
"syscall"
// #include <sys/sysmacros.h>
"C"
)
@jim3ma
jim3ma / es.py
Last active November 29, 2019 13:12 — forked from arturo-c/python-to-es.py
Operate ElasticSearch with AWS sigv4 in python
import base64
import datetime
import json
import os
import time
import traceback
import urlparse
import botocore.auth
import botocore.awsrequest
@jim3ma
jim3ma / mount-ram.sh
Created September 24, 2020 12:56 — forked from koshigoe/mount-ram.sh
Like tmpfs in Mac OSX
#!/bin/sh
# This program has two feature.
#
# 1. Create a disk image on RAM.
# 2. Mount that disk image.
#
# Usage:
# $0 <dir> <size>
#
@jim3ma
jim3ma / retry.sh
Created November 15, 2021 06:52 — forked from felipou/retry.sh
Retry command
#!/bin/bash
#
# Created by Felipe Machado - 2016/02/14
#
# A retry command for bash
# Retries the given command up to MAX_RETRIES, with an interval of SLEEP_TIME
# between each retry. Just put it on your bash_profile and be happy :)
# Usage:
# retry [-s SLEEP_TIME] [-m MAX_RETRIES] COMMAND_WITH_ARGUMENTS
#

Use Proxy for Git/GitHub

Generally, the Git proxy configuration depends on the Git Server Protocal you use. And there're two common protocals: SSH and HTTP/HTTPS. Both require a proxy setup already. In the following, I assume a SOCKS5 proxy set up on localhost:1080. But it can also be a HTTP proxy. I'll talk about how to set up a SOCKS5 proxy later.

SSH Protocol

When you do git clone ssh://[user@]server/project.git or git clone [user@]server:project.git, you're using the SSH protocal. You need to configurate your SSH client to use a proxy. Add the following to your SSH config file, say ~/.ssh/config:

ProxyCommand nc -x localhost:1080 %h %p
@jim3ma
jim3ma / ioctlsnoop.bt
Last active December 19, 2022 05:57
ioctl bpftrace script
#!/usr/bin/env bpftrace
/*
* ioctlsnoop Trace ioctl() syscalls.
* For Linux, uses bpftrace and eBPF.
*
* USAGE: ioctlsnoop.bt
*
* Copyright 2022 Jim Ma.
* Licensed under the Apache License, Version 2.0 (the "License")
*