Skip to content

Instantly share code, notes, and snippets.

@qingfeng
qingfeng / SlotMachine
Created December 27, 2017 05:47 — forked from imontantes/SlotMachine
Slot Machine in Python
import random
print('''Welcome to the Slot Machine Simulator
You'll start with $50. You'll be asked if you want to play.
Answer with yes/no. you can also use y/n
No case sensitivity in your answer.
For example you can answer with YEs, yEs, Y, nO, N.
To win you must get one of the following combinations:
BAR\tBAR\tBAR\t\tpays\t$250
BELL\tBELL\tBELL/BAR\tpays\t$20
PLUM\tPLUM\tPLUM/BAR\tpays\t$14
@qingfeng
qingfeng / banned.py
Created November 18, 2012 09:13 — forked from Cairnarvon/banned.py
Web service that keeps track of bad images using perceptual hashes and a bloom filter, to be used by imageboards and the like. (Proof of concept.)
#!/usr/bin/python
import argparse
import cgi
import math
import os
import sys
from PIL import Image
import pybloomfilter # https://github.com/axiak/pybloomfiltermmap
@qingfeng
qingfeng / django_jinja.py
Created July 29, 2011 13:48 — forked from rozza/django_jinja.py
Django 1.2 and Jinja2 loader
"""
Using Jinja2 with Django 1.2
Based on: http://djangosnippets.org/snippets/2063/
To use:
* Add this template loader to settings: `TEMPLATE_LOADERS`
* Add template dirs to settings: `JINJA2_TEMPLATE_DIRS`
If in template debug mode - we fire the template rendered signal, which allows
debugging the context with the debug toolbar. Viewing source currently doesnt
try:
from django.core.management import setup_environ
import settings
setup_environ(settings)
print 'imported django settings'
try:
exec_strs = ["from %s.models import *"%apps for apps in settings.INSTALLED_APPS ]
for x in exec_strs:
try:
exec(x)
# encoding: utf-8
import urllib2
import cookielib
import re
import xml.dom as dom
import xml.dom.minidom as minidom
from BeautifulSoup import BeautifulSoup, Tag, Comment, NavigableString
from __future__ import with_statement
import os,sys
def find_condition(filename,condition):
with open(filename) as f:
for i in f:
i = i.strip()
data = i.split('|')
if condition == data[2]:
yield i
javascript:(function(d,s,h,B,X,z,c,n,i,b,x,y,m,u,f,T,W,H,V,K){function Z(n){with(n=n.style)position='absolute',left=0,top=0,width=W,height=H,zIndex=1e6;return n}W=X*s,H=h*s;with(Z(n=d.createElement('div')))background='#ffe',opacity=0.7;Z(c=d.createElement('canvas')),c.width=W,c.height=H;d.body.insertBefore(c,d.body.firstChild),d.body.insertBefore(n,c);c=c.getContext('2d'),c.fillStyle='#000';i=X;while(--i>=0)z[i]=[];function R(){return 0|Math.random()*B.length}function r(x,y){c.fillRect(x*s+1,y*s+1,s-2,s-2)}function t(x,y,b){i=4;while(i--)r(x+(b&3),y+((b>>=2)&3)),b>>=2}function D(){n=h;while(--n>0){m=X;while(--m>=0){z[m][n]&&r(m,n)}}}function C(x,y,b){i=4;do{m=x+(b&3),n=y+((b>>=2)&3),b>>=2;}while(m>=0&&m<X&&n<h&&!z[m][n]&&--i);return i}function l(){if(!(T++%2510))if(C(x,y+1,b)){if(++V>3){i=4;while(i--)z[x+(b&3)][y+((b>>=2)&3)]=1,b>>=2;b=B[R()];x=4,y=V=0;}}else{V=0,++y};K==72?C(x-1,y,b)||x--:K==76?C(x+1,y,b)||x++:K==74?T=0:0;c.clearRect(0,0,W,H);D();t(x,y,b)}K=T=y=0,x=4,b=B[R()],d.addEventListener('keydown',fun
@qingfeng
qingfeng / snippet.sc
Created February 7, 2009 16:40 — forked from anonymous/snippet.sc
First Python 3000 Script
# encoding: utf-8
import hashlib
import sys
if __name__ == '__main__':
i = bytes(sys.argv[1],'utf8')
k = hashlib.md5(i).hexdigest()
print(k)
#!/usr/bin/env python
import vobject
from cStringIO import StringIO
import os, sys, string
'''
Simple script to parse an Apple Addressbook export file and
turn it into a Mutt aliases file
@qingfeng
qingfeng / snippet.txt
Created November 25, 2008 07:47 — forked from anonymous/snippet.txt
自动访客程序
#!/usr/bin/env python
# encoding: utf-8
from twill import *
import urllib2,re
USERNAME = 'YOUR USERNAME'
PASSWORD = 'YOUR PASSWORD'
BLOG_LIST = [