Skip to content

Instantly share code, notes, and snippets.

@comfuture
comfuture / decorator.py
Created January 15, 2011 06:51
python decorator trick (can have options or not)
def fb_session_required(arg1=True):
verify = arg1 is True
def decorate(f):
@wraps(f)
def check(*args, **kwargs):
if not request.values.has_key('fb_sig_session_key'):
return "Requires facebook session", 403
if verify and get_access_token(use_cache=False):
return "Requires valid facebook session", 403
return f(*args, **kwargs)
@comfuture
comfuture / PList.as
Created January 27, 2011 01:49
simple plist parser for actionscript
package maroo.codec
{
import flash.utils.ByteArray;
import mx.utils.Base64Decoder;
public class PList
{
public static function parse(source:XML):Object
{
switch (source.name().localName) {
@comfuture
comfuture / backup.sh
Created February 9, 2011 08:46
backup daily to remote host, and delete old backups smarter
#!/bin/bash
date=`date "+%Y-%m-%dT%H_%M_%S"`
HOME=/YOUR/LOCALHOME
SERVER=ID@HOST
DIR=backup
rsync -azP \
--bwlimit=500 \
--delete \
--delete-excluded \
@comfuture
comfuture / gist:827368
Created February 15, 2011 10:29
amazon s3 policy by referrer example
{
"Version":"2011-02-15",
"Id":"only allowed referers",
"Statement":[
{
"Sid":"Allow get requests referred by maroo.info and apps.facebook.com",
"Effect":"Allow",
"Principal":"*",
"Action":"s3:GetObject",
"Resource":"arn:aws:s3:::static.maroo.info/*",
@comfuture
comfuture / policy.json
Created February 15, 2011 11:08
s3 bucket policy - working
{
"Version": "2008-10-17",
"Id": "static.maroo.info",
"Statement": [
{
"Sid": "2- Allow referrers from my domain.",
"Effect": "Deny",
"Principal": {
"AWS": "*"
},
@comfuture
comfuture / brightnesscontrast.pbk
Created February 18, 2011 09:21
filter for brightness and contrast
<languageVersion : 1.0;>
kernel BrightContrast
< namespace : "jp.ncsoft.image.filters";
vendor : "maroo";
version : 1;
description : "adjust contrast and brightness";
>
{
@comfuture
comfuture / server.js
Created April 5, 2011 06:07
less complier service
var less = require('./less');
with (require('./nano')) {
get(/\/lessc\/(.*)/, function(match) {
try {
var _parsed = URL.parse(match[1], true);
var client = make_client(80, _parsed.host);
var less_req = client.request('GET', _parsed.pathname, {'host': _parsed.host});
less_req.addListener('response', function(less_resp) {
@comfuture
comfuture / ircian.js
Created April 13, 2011 08:38
say hello to ircian bot
exports.plugin = function(bot) {
bot.on('join', function(chan, nick) {
if (nick == 'ircian') {
bot.talk(chan, [[
nick + ':나가!',
nick + ':나가지마!',
nick + ':안녕',
nick + ':메롱'
]]);
}
@comfuture
comfuture / wput.py
Created April 17, 2011 14:01
put a file or url to amazon s3 service
#!/usr/bin/python
import mimetypes
import urllib
import os.path
import sys
import S3 # grep http://developer.amazonwebservices.com/connect/entry.jspa?externalID=134&categoryID=47
AWS_ACCESS_KEY_ID = '****'
AWS_SECRET_ACCESS_KEY = '****'
BUCKET_NAME = '****'
@comfuture
comfuture / recover.py
Created April 19, 2011 06:25
recover broken shiftjis filenames
#!/usr/bin/python
import os
import glob
import re
def recover(s, e='sjis'):
return re.sub(r'\\(...)', lambda m: chr(int(m.group(1), 8)), s).decode(e)
def rename(f):