Skip to content

Instantly share code, notes, and snippets.

View tnlin's full-sized avatar
🎯
Focusing

Tony Lin tnlin

🎯
Focusing
View GitHub Profile
@esperlu
esperlu / mysql2sqlite.sh
Created April 27, 2011 05:46
MySQL to Sqlite converter
#!/bin/sh
# Converts a mysqldump file into a Sqlite 3 compatible file. It also extracts the MySQL `KEY xxxxx` from the
# CREATE block and create them in separate commands _after_ all the INSERTs.
# Awk is choosen because it's fast and portable. You can use gawk, original awk or even the lightning fast mawk.
# The mysqldump file is traversed only once.
# Usage: $ ./mysql2sqlite mysqldump-opts db-name | sqlite3 database.sqlite
# Example: $ ./mysql2sqlite --no-data -u root -pMySecretPassWord myDbase | sqlite3 database.sqlite
@jmoiron
jmoiron / crawler.py
Created May 27, 2011 20:37
Simple gevent/httplib2 web crawler.
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""Simple async crawler/callback queue based on gevent."""
import traceback
import logging
import httplib2
import gevent
@yosemitebandit
yosemitebandit / yupyupnope.conf
Created September 29, 2011 23:37
nginx config file for flask app (behind gunicorn) with ssl
server {
listen 80;
server_name www.yupyupnope.com;
rewrite ^/(.*) https://yupyupnope.com/$1 permanent;
}
server {
listen 80;
server_name yupyupnope.com;
rewrite ^/(.*) https://yupyupnope.com/$1 permanent;
@rednaxelafx
rednaxelafx / DirectMemorySize.java
Created January 11, 2012 07:18
An Serviceability-Agent based tool to see stats of NIO direct memory, as an alternative on JDK6 without JMX support for direct memory monitoring. Only works on JDK6; to work on JDK7 will need some tweaking because static variables are moved to Java mirror
import java.io.*;
import java.util.*;
import sun.jvm.hotspot.memory.*;
import sun.jvm.hotspot.oops.*;
import sun.jvm.hotspot.debugger.*;
import sun.jvm.hotspot.runtime.*;
import sun.jvm.hotspot.tools.*;
import sun.jvm.hotspot.utilities.*;
public class DirectMemorySize extends Tool {
@gorlum0
gorlum0 / ex2.py
Created January 28, 2012 09:43
ml-class - ex2 (python)
#!/usr/bin/env python
from __future__ import division
import numpy as np
import matplotlib.pyplot as plt
from scipy import optimize
from numpy import newaxis, r_, c_, mat, e
from numpy.linalg import *
def plotData(X, y):
#pos = (y.ravel() == 1).nonzero()
@gorlum0
gorlum0 / ex2_reg.py
Created January 28, 2012 09:45
ml-class - ex2_reg (python)
#!/usr/bin/env python
from __future__ import division
import numpy as np
import matplotlib.pyplot as plt
from scipy import optimize
from numpy import newaxis, r_, c_, mat, e
from numpy.linalg import *
def plotData(X, y):
pos = (y.ravel() == 1).nonzero()
@nicerobot
nicerobot / README.md
Last active June 18, 2024 19:46
Mac OS X uninstall script for packaged install of node.js from https://stackoverflow.com/a/9287292/23056

To run this, you can try:

curl -ksO https://gist.githubusercontent.com/nicerobot/2697848/raw/uninstall-node.sh
chmod +x ./uninstall-node.sh
./uninstall-node.sh
rm uninstall-node.sh
@MohamedAlaa
MohamedAlaa / tmux-cheatsheet.markdown
Last active July 24, 2024 17:56
tmux shortcuts & cheatsheet

tmux shortcuts & cheatsheet

start new:

tmux

start new with session name:

tmux new -s myname
@yu-lu
yu-lu / LuYU426.Games.Snake.py
Last active December 15, 2015 01:39
This is a 99 lines snake game written upon IronPython. This simple game is tested with both MacOS and Windows, code is slightly different, see comment inline. This is intended to fit in 99 lines, so code is neither well formatted nor well read, please don't blame me on this :P
import os, time, random
from collections import defaultdict
from System import Console, ConsoleColor, ConsoleKey
from System.Threading import Thread, ThreadStart
class Screen(object):
red = ConsoleColor.Red; green = ConsoleColor.Green; blue = ConsoleColor.Blue;black = ConsoleColor.Black
dimension = (21,39)
def __update_input(self):
mapping = defaultdict(lambda: None,
@miguelgrinberg
miguelgrinberg / rest-server.py
Last active March 29, 2024 09:05
The code from my article on building RESTful web services with Python and the Flask microframework. See the article here: http://blog.miguelgrinberg.com/post/designing-a-restful-api-with-python-and-flask
#!flask/bin/python
from flask import Flask, jsonify, abort, request, make_response, url_for
from flask_httpauth import HTTPBasicAuth
app = Flask(__name__, static_url_path = "")
auth = HTTPBasicAuth()
@auth.get_password
def get_password(username):
if username == 'miguel':