Skip to content

Instantly share code, notes, and snippets.

View yijxiang's full-sized avatar
🏠
Working from home

yijun xiang yijxiang

🏠
Working from home
View GitHub Profile
#!/usr/bin/env bash
[ $(id -u) = 0 ] || { echo "You must be root (or use 'sudo')" ; exit 1; }
fwrule=`ipfw -a list | grep "deny ip from any to any"`
fwrule_id=`echo $fwrule | awk '{ print $1 }'`
if [ "$fwrule" != "" ]; then
echo "Found blocking firewall rule: $(tput setaf 1)${fwrule}$(tput sgr0)"
printf "Deleting rule ${fwrule_id} ... "
ipfw delete ${fwrule_id}
@yijxiang
yijxiang / gist:096fdd32c55a5cab1e53c869bfcab306
Created May 17, 2016 23:35 — forked from bortzmeyer/gist:1284249
The only simple way to do SSH in Python today is to use subprocess + OpenSSH...
#!/usr/bin/python
# All SSH libraries for Python are junk (2011-10-13).
# Too low-level (libssh2), too buggy (paramiko), too complicated
# (both), too poor in features (no use of the agent, for instance)
# Here is the right solution today:
import subprocess
import sys
@yijxiang
yijxiang / Flask-SqlAlchemy-Many-to-Many.py
Created July 15, 2016 04:42 — forked from kphretiq/Flask-SqlAlchemy-Many-to-Many.py
A (hopefully) simple demo of how to do many-to-many relationships using Flask-SQLAlchemy
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import json
from flask import Flask, url_for
from flask_sqlalchemy import SQLAlchemy
"""
Flask-SQLAlchemy many-to-many relationship using helper table
http://flask-sqlalchemy.pocoo.org/2.1/models/
Hippies love their dogs.
@yijxiang
yijxiang / ipam-tools.md
Created May 21, 2018 01:01 — forked from regnauld/ipam-tools.md
Overview of IPAM/DCIM tools - July 2016
@yijxiang
yijxiang / pyenv+virtualenv.md
Created September 19, 2018 03:12 — forked from eliangcs/pyenv+virtualenv.md
Cheatsheet: pyenv, virtualenvwrapper, and pip

Cheatsheet: pyenv, virtualenvwrapper, and pip

Installation (for Mac OS)

Install pyenv with brew

brew update
brew install pyenv
@yijxiang
yijxiang / gae_handler.py
Created December 25, 2018 03:22 — forked from ykessler/gae_handler.py
Python logging handlers
class GAEHandler(logging.Handler):
"""
Logging handler for GAE DataStore
"""
def emit(self, record):
from google.appengine.ext import db
class Log(db.Model):
name = db.StringProperty()
@yijxiang
yijxiang / masq.sh
Created January 19, 2019 08:09 — forked from mowings/masq.sh
script to get xet xhyve working with all vpn interfaces
#!/bin/bash
interfaces=( $(netstat -in | egrep 'utun\d .*\d+\.\d+\.\d+\.\d+' | cut -d ' ' -f 1) )
rulefile="rules.tmp"
echo "" > $rulefile
sudo pfctl -a com.apple/tun -F nat
for i in "${interfaces[@]}"
do
RULE="nat on ${i} proto {tcp, udp, icmp} from 192.168.64.0/24 to any -> ${i}"
echo $RULE >> $rulefile
done
-- eve-ng_wireshark.scpt by Matt Haedo --
-- Fork of Stuart Fordham's UNL_WiresharkV2 --
-- https://www.802101.com/unetlab-and-wireshark-for-osx-update --
-- To use, copy this code, paste into Apple Script Editor, and save as .app --
on open location this_URL
set get_date to do shell script "date +%Y%m%d-%H%M%S"
set cap_URL to this_URL
set AppleScript's text item delimiters to {"/"}
set new_cap_HOST to text item 3 of cap_URL
@yijxiang
yijxiang / ratelimiter.py
Created January 13, 2020 04:34 — forked from pquentin/ratelimiter.py
How do you rate limit calls with aiohttp?
#!/usr/bin/env python3
import asyncio
import time
import aiohttp
START = time.monotonic()
@yijxiang
yijxiang / mac-setup-redis.md
Created January 15, 2020 03:08 — forked from tomysmile/mac-setup-redis.md
Brew install Redis on Mac

type below:

brew update
brew install redis

To have launchd start redis now and restart at login:

brew services start redis