Skip to content

Instantly share code, notes, and snippets.

View abraham's full-sized avatar
thanks a latte

Abraham Williams abraham

thanks a latte
View GitHub Profile
@abraham
abraham / migrate.markdown
Created August 10, 2010 02:17
Terminal commands for migrating sites

Dump a MySQL database to a file

mysqldump -h example.com -u username -p database > file.sql

Import sql file into MySQL

mysql -u username -p
mysql: source file.sql

Compress a directory into a tar file and maintain permissions

@abraham
abraham / facebook.py
Created August 14, 2010 08:45
Finds who among your Facebook friends you have the most common interests and likes with
#!/usr/bin/python -tt
# MIT licensed by Abraham Williams - http://abrah.am
# Pulls your Facebook friends likes and interest and finds who you have the most in common with.
import urllib, json, sys
graph_url = 'https://graph.facebook.com/'
def print_intersect_count(access_token):
tally = {}
@abraham
abraham / chargify-require-phone.js
Created August 20, 2010 02:43
Require phone numbers on Chargify hosted pages.
// Past into the custom javascript field for your hosted page to use javascript to require phone numbers.
var phoneLabel = jQuery('[for=subscription_customer_attributes_phone]');
phoneLabel.text('* Phone')
phoneInput = jQuery('#subscription_customer_attributes_phone');
jQuery('#hosted-payment-form').submit(function(){
if(phoneInput.val() == '') {
phoneLabel.text('* Phone: cannot be blank.')
phoneLabel.css('color', 'red');
phoneInput.click(function(){
@abraham
abraham / access_token.js
Created August 20, 2010 08:53
OAuth 2 with the Twitter API
localStorage.getItem("twttr_anywhere");
// "9436992-QKOV6cNsfeRe9Kagyy4AmQF7WX2efs3rRDgyEy7Bvsfeaf"
function fillAnywhereTweetBox(url) {
twttr.anywhere("1", function (twitter) {
var name = getBloggerPageName();
if (name == "the.hackerConundrum") {
var content = "Reading \"" + name +"\" - " + url + " by @abraham"
} else {
var content = "Reading \"" + name +"\" - " + url + " by @abraham"
}
twitter("#twitter-anywhere-gadget").tweetBox({
counter: 0,
@abraham
abraham / twitter.php
Created September 4, 2010 03:40
How to tweet with OAuth in three lines
<?php
// Download the latest version of TwitterOAuth from http://github.com/abraham/twitteroauth/downloads
// Unpack the download and place the twitteroauth.php and OAuth.php files in the same directory as this file.
// Register an application at http://dev.twitter.com/apps and from your new apps page get "my access token".
require_once('twitteroauth.php');
$connection = new TwitterOAuth('app consumer key', 'app consumer secret', 'my access token', 'my access token secret');
$status = $connection->post('statuses/update', array('status' => 'text to be tweeted'));
@abraham
abraham / recent-comments.js
Created September 5, 2010 05:43
Display recent comments from a blogger site.
<dl id="recentComments"></dl>
<script type="text/javascript">
function renderComments (json) {
var list = document.getElementById("recentComments");
for (var i = 0; i < json.feed.entry.length; ++i) {
var entry = json.feed.entry[i];
var dt = document.createElement("DT");
var dd = document.createElement("DD");
var href;
@abraham
abraham / install.sh
Created September 8, 2010 04:02
user-data script to setup ec2 ubuntu servers
#!/bin/bash
set -e -x
export DEBIAN_FRONTEND=noninteractive
apt-get update && apt-get upgrade -y
tasksel install lamp-server
apt-get install git-core
echo "Please remember to set the MySQL root password!"
@abraham
abraham / bridgecode.php
Created September 10, 2010 05:51
Example code for getting an OAuth 1.0a access_token from Twitter @anywhere users.
<?php
// Download TwitterOAuth from http://github.com/abraham/twitteroauth.
require_once('twitteroauth/twitteroauth.php');
// Get consumer keys from http://dev.twitter.com/apps.
$consumer_key = '';
$consumer_secret = '';
$oauth_bridge_code = '';
@abraham
abraham / update.php
Created September 22, 2010 17:18
Simple script to post a Tweet using XML and OAuth
<?php
// Download the latest version of http://github.com/abraham/twitteroauth/downloads
// Move twitteroauth.php and OAuth.php into this directory.
// Register an application at http://dev.twitter.com/apps.
// Get a user access token as described in http://dev.twitter.com/pages/oauth_single_token.
require_once('twitteroauth.php');
$connection = new TwitterOAuth('app consumer key', 'app consumer secret', 'my access token', 'my access token secret');
$connection->format = 'xml';
$status = $connection->post('statuses/update', array('status' => $message));