Skip to content

Instantly share code, notes, and snippets.

View masom's full-sized avatar
💭
I may be slow to respond.

Martin Samson masom

💭
I may be slow to respond.
  • Shopify
  • Ottawa, Canada
View GitHub Profile
@mikeyk
mikeyk / redis_session_backend.py
Created April 8, 2011 18:01
A redis backend for Django Sessions, tested on Django 1.3+
from django.contrib.sessions.backends.base import SessionBase, CreateError
from django.conf import settings
from django.utils.encoding import force_unicode
import redis
class SessionStore(SessionBase):
""" Redis store for sessions"""
def __init__(self, session_key=None):
self.redis = redis.Redis(
@felixge
felixge / image_resize.js
Created May 20, 2011 18:07
On demand image resizing with node.js in
// Usage: http://localhost:8080/image.jpg/100x50
var http = require('http');
var spawn = require('child_process').spawn;
http.createServer(function(req, res) {
var params = req.url.split('/');
var convert = spawn('convert', [params[1], '-resize', params[2], '-']);
res.writeHead(200, {'Content-Type': 'image/jpeg'});
convert.stdout.pipe(res);
@pamelafox
pamelafox / friendsearch.html
Created June 2, 2011 18:53
Facebook API + jQuery Autosuggest
<!doctype html>
<head>
<link rel="stylesheet" href="/css/style.css">
<body>
<input class="friend-search"></input>
<div id="fb-root"></div>
<script>window.jQuery || document.write("<script src='/js/libs/jquery-1.5.1.min.js'>\x3C/script>")</script>
<script src="/js/jquery.autosuggest.js"></script>
@pamelafox
pamelafox / gist:1006753
Created June 3, 2011 17:35
Sendgrid Python Web API example
import urllib2, urllib
import logging
def send_mail_sendgrid(from, to, subject, body):
base_url = 'https://sendgrid.com/api/mail.send.json'
params = {
'api_user': 'you@you.com',
'api_key': 'yourpassword',
'from': from,
'to': to,
@felixge
felixge / command.sh
Created October 29, 2011 13:43
Bash stuff for fighting a weak DOS attack
# Here a few bash one-liners that helped me analyze / fight a weak DOS attack against debuggable.com. Mostly for future reference.
# The attacker was opening lots of tcp connections without sending data, I believe it's called a SYN flood, see: http://tools.ietf.org/html/rfc4987#section-3.2
# Step 0: Check what is going on at port 80
$ netstat -tan | grep ':80 ' | awk '{print $6}' | sort | uniq -c
# Step 1: Increase the number of available fds
$ ulimit -n 32000
# Step 2: Restart your webserver, for me:
@pamelafox
pamelafox / gist:1469925
Created December 13, 2011 01:10
Click/touchstart wrapper
function addClickHandler(dom, callback, logThis) {
if (useTouchEvents()) {
dom.each(function() {
$(this).unbind('tap', callback);
$(this).bind('tap', callback);
$(this).bind('touchstart', function(e) {
var item = e.currentTarget;
if (ISTOUCHING) return;
/**
*
* Copyright © 2009, 2010 Apple Inc. All rights reserved.
*
**/
/* iAd JS Version:1.1 */
.ad-view {
position:absolute;
top:0;
@nateabele
nateabele / routes.php
Last active June 16, 2017 13:05
Lithium continuation route examples
<?php
/**
* Continuation routing examples. Handles URLs in the following forms:
*
* /posts
* /en/posts
* /admin/posts
* /admin/en/posts
* /admin/en/posts.json
* /admin/en/posts/4ef16ccc7f8b9aa331000064.json
@pamelafox
pamelafox / render_index.py
Created December 24, 2011 00:12
PhoneGap Index Renderer (Jinja2)
import sys
sys.path.append('/Library/Python/2.7/site-packages')
from jinja2 import Environment, FileSystemLoader
if __name__ == "__main__":
env = Environment(loader=FileSystemLoader('application/templates/'))
template = env.get_template('phonegap/index.html')
print template.render(debug=False, mobile=True, native=True)
@pamelafox
pamelafox / phonegap.html
Created December 24, 2011 00:16
Phonegap Index (Jinja2)
<!doctype html>
<html>
<head>
<meta name="viewport" content="initial-scale=1.0, user-scalable=no, width=device-width" />
<meta name="apple-mobile-web-app-capable" content="yes" />
<title>everyday.io</title>
{% if g and g.debug %}
<link rel="stylesheet" href="css/colorslider.css" />
<link rel="stylesheet" href="css/dateinput.css" />
<link rel="stylesheet" href="css/bootstrap-1.3.0.min.css">