Skip to content

Instantly share code, notes, and snippets.

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

greatghoul greatghoul

🏠
Working from home
View GitHub Profile
@epicserve
epicserve / save_cookie_example.py
Created August 3, 2011 17:04
Example of how to save a cookie for logging into a website.
@longfin
longfin / gist:1616353
Created January 15, 2012 16:33
Flask session
# from http://flask.pocoo.org/docs/quickstart/#sessions
from flask import Flask, session, redirect, url_for, escape, request
app = Flask(__name__)
@app.route('/')
def index():
if 'username' in session:
return 'Logged in as %s' % escape(session['username'])
@wynemo
wynemo / urllib2_auth.py
Created March 21, 2012 17:03
urllib2 basic auth
# quoted from http://www.wkoorts.com/wkblog/2008/10/27/python-proxy-client-connections-requiring-authentication-using-urllib2-proxyhandler/
# urllib2_proxy_handler.py
#
# Author: Wayne Koorts
# Date: 27/10/2008
#
# Example for using urllib2.urlopen() with a proxy server requiring authentication
import urllib2
@013231
013231 / placeholder.py
Created October 11, 2012 13:19
Create a placeholder picture.
#!/usr/bin/env python
from tornado.web import Application, RequestHandler
from tornado.ioloop import IOLoop
from PIL import Image, ImageDraw, ImageFont, ImageColor
import cStringIO
import re
fontPath = '/Library/Fonts/Arial.ttf'
port = 8080
@greatghoul
greatghoul / gdg-sites.md
Last active December 31, 2015 11:48
收集全球的GDG组织的网站

GDG组织网站收集

本文用于收集全球的GDG组织用于筹划或者展示活动的网站,以此为西安GDG的网站规划作参考。

GDG X

介绍中没有详细写明这是哪个 GDG 组织,但是这个组织中具有参考价值的项目还是比较多的。

zh-CN:
admin:
home:
name: "首页"
pagination:
previous: "« 上一页"
next: "下一页 »"
truncate: "…"
misc:
filter_date_format: "mm/dd/yy" # a combination of 'dd', 'mm' and 'yy' with any delimiter. No other interpolation will be done!
@justan
justan / qrcode.js
Created June 21, 2012 09:01
a qrcode bookmarklet(二维码小书签)
//a qrcode bookmarklet(二维码小书签)
//javascript:(function(d){var b=d.createElement("textarea"),c,f=!!d.all,a,e="http://qrcode.kaywa.com/img.php?s=5&d=%s";(c=d.getElementById("_qrcode__"))?(b=c,a=b.style,a.display=""):(a=b.style,b.id="_qrcode__",d.body[f?"attachEvent":"addEventListener"]((f?"on":"")+"click",function(){a.display="none"},!0),a.zIndex=9999,a.position="fixed",a.top=0,a.left=0,a.width="100%",a.height="100%",d.body.appendChild(b));c=function(){var a,b=d.selection,c=d.activeElement,e=top.getSelection,f=c&&c.selectionEnd;f?a=c.value.substring(c.selectionStart, f):e&&(a=e()+"");b&&(a=b.createRange().text);return a=a||location.href}();b.title=c;e=e.replace("%s",encodeURIComponent(c));a.color='#fff';a.background="rgba(0, 0, 0, 0.3) url("+e+") no-repeat center";b.select()})(document);
//original code
(function(doc){
var qrcode = doc.createElement('textarea'), tmp,
ie = !!doc.all, style, txt,
qrimage = 'http://qrcode.kaywa.com/img.php?s=5&d=%s',
id = '_qrcode__';
@wilsaj
wilsaj / hello_soap_flask.py
Created February 23, 2011 19:37
Flask + Soaplib
import soaplib
from soaplib.core.service import rpc, soap, DefinitionBase
from soaplib.core.model.primitive import String, Integer
from soaplib.core.server import wsgi
from soaplib.core.model.clazz import Array
from flask import Flask
flask_app = Flask(__name__)
@dunckr
dunckr / _bootstrap.scss
Created February 20, 2015 16:55
bootstrap-sass from npm install
// Core variables and mixins
@import "../../node_modules/bootstrap-sass/assets/stylesheets/bootstrap/variables";
@import "../../node_modules/bootstrap-sass/assets/stylesheets/bootstrap/mixins";
// Reset and dependencies
@import "../../node_modules/bootstrap-sass/assets/stylesheets/bootstrap/normalize";
@import "../../node_modules/bootstrap-sass/assets/stylesheets/bootstrap/print";
@import "../../node_modules/bootstrap-sass/assets/stylesheets/bootstrap/glyphicons";
// Core CSS
@bricker
bricker / promises.md
Last active March 14, 2018 00:33
Promises in Rails callbacks, using after_save and after_commit together.

"Russian-Doll Caching" is great. It embraces the Rails (and Ruby) goal to "make the developer happy". And it does. Not having to worry about cache expiration is superb.

It has its limits, though. If you're trying to avoid any database queries, russian-doll caching will not work for you. If you are trying to represent thousands, or even hundreds, of objects under a single cache fragment, russian-doll caching is not the best option.

We use it whenever it makes sense, but sometimes we just have to bite the bullet and expire a cache fragment manually. When you want to start manually expiring cache on a fairly busy website, you have to start considering race conditions. I recently ran into the following scenario:

class Post < ActiveRecord::Base
  after_save :expire_cache