Skip to content

Instantly share code, notes, and snippets.

View philfreo's full-sized avatar

Phil Freo philfreo

View GitHub Profile
// ==UserScript==
// @name Gmail "From" Address auto-selector
// @version 0.18
// @description Looks in your "To" field and sees if you have an email address in your "From" addresses with the same domain. Changes <select> onblur
// @author Andrew Sutherland, https://github.com/asuth
// @include http://mail.google.com/*
// @include https://mail.google.com/*
// @include http://*.mail.google.com/*
// @include https://*.mail.google.com/*
// ==/UserScript==
@philfreo
philfreo / class.cconvert.js
Created June 4, 2011 01:01
Chinese Simplified<->Traditional Converter (PHP)
//Edited by 168funpc
var Default_isFT = 0 //ĬÈÏÊÇ·ñ·±Ì壬0-¼òÌ壬1-·±Ìå
var StranIt_Delay = 50 //·­ÒëÑÓʱºÁÃ루ÉèÕâ¸öµÄÄ¿µÄÊÇÈÃÍøÒ³ÏÈÁ÷³©µÄÏÔÏÖ³öÀ´£©
//£­£­£­£­£­£­£­´úÂ뿪ʼ£¬ÒÔϱð¸Ä£­£­£­£­£­£­£­
//ת»»Îı¾
function StranText(txt,toFT,chgTxt)
{
if(txt==""||txt==null)return ""
@philfreo
philfreo / QueryStringTest.php
Created June 22, 2011 19:44
add_querystring_var() and remove_querystring_var() improvements, with tests
<?php
class QueryStringTest extends PHPUnit_Framework_TestCase {
/**
* @covers remove_querystring_var
*/
public function testRemoveQueryStringVar() {
// tests without any other querystring params
@philfreo
philfreo / utf8.php
Created June 24, 2011 19:25
Convert between Unicode code points and UTF-8
/* ***** BEGIN LICENSE BLOCK *****
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Netscape Public License
* Version 1.1 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
@philfreo
philfreo / gist:2321650
Created April 6, 2012 17:58
mysqldump cron
#!/bin/sh
# CRON
## delete encrypted backups older than 5 days
#55 3 * * * find /path/to/backups-enc -mtime +5 -exec rm {} \;
## delete un-encrypted backups older than 1 days
#55 3 * * * find /path/to/backups -mtime +0 -exec rm {} \;
## database dump at 4am UTC = 8pm PST (9pm PDT)
#0 4 * * * /path/to/this/script
@philfreo
philfreo / model.js
Last active October 6, 2015 21:37
Backbone Model mutators / computed properties
var Model = Backbone.Model.extend({
/**
* Override main attribute getter to handle mutators.
* Looks for an object on the model called 'mutators', keyed by key name,
* with values of either the getter function or an object like:
* { get: function() {}, set: function() {} }
*/
get: function(attr) {
var val,
@philfreo
philfreo / gist:3148064
Created July 20, 2012 01:21 — forked from mattheworiordan/gist:1037984
Backbone patch to defer update method requests when new create requests are not complete on a model
// Queue of Backbone.Model save()s so that we don't issue multiple POSTs while waiting for
// the first one to come back. The first save() will always POST and the second will always PUT now.
// https://github.com/documentcloud/backbone/issues/345
// https://gist.github.com/1037984 and https://gist.github.com/gists/3148064
(function() {
function proxyAjaxEvent(event, options, dit) {
var eventCallback = options[event];
options[event] = function() {
// check if callback for event exists and if so pass on request
if (eventCallback) { eventCallback(arguments) }
@philfreo
philfreo / gist:3148065
Created July 20, 2012 01:21 — forked from mattheworiordan/gist:1037984
Backbone patch to defer update method requests when new create requests are not complete on a model
(function() {
function proxyAjaxEvent(event, options, dit) {
var eventCallback = options[event];
options[event] = function() {
// check if callback for event exists and if so pass on request
if (eventCallback) { eventCallback(arguments) }
if (eventCallback) { eventCallback.apply(dit, arguments); }
dit.proxyProcessQueue(); // move onto next save request in the queue
}
}
@philfreo
philfreo / gist:3208678
Created July 30, 2012 17:52
Gzip files in a directory, upload it to s3 for Cloudfront (far futures)
# imgs don't need to be gzipped
s3cmd put -c config/.s3cfg-prod-static --acl-public --guess-mime-type --add-header "Cache-Control:public, max-age=31536000" -r static/img s3://my-bucket-name/
# js/css does need gzipping
rm -rf static/built-gz;
cp -a static/built/ static/built-gz/;
find static/built-gz -type f | while read -r x; do gzip -9 -c "$x" > "$x.gz"; mv "$x.gz" "$x"; done;
s3cmd put -c config/.s3cfg-prod-static --acl-public --guess-mime-type --add-header "Cache-Control:public, max-age=31536000" --add-header "Content-Encoding: gzip" -r static/built-gz/ s3://my-bucket-name/built/
@philfreo
philfreo / bucket_policy.js
Created October 6, 2012 01:27
AWS S3 bucket policy to make all files public (+CORS)
{
"Statement": [
{
"Sid": "AllowPublicRead",
"Effect": "Allow",
"Principal": {
"AWS": "*"
},
"Action": "s3:GetObject",
"Resource": "arn:aws:s3:::bucket_name_here/*"