Skip to content

Instantly share code, notes, and snippets.

@mungomash
mungomash / gist:1575865
Created January 7, 2012 20:08
Adding additional methods in Ruby
require 'date'
class Weeks
def initialize(number)
@number = number
end
def ago
return Date.today - (@number * 7)
end
end
@mungomash
mungomash / gist:1575696
Created January 7, 2012 19:15
Git cheat sheet
# undo a commit (file changes and index changes preserved)
git reset --soft HEAD^
# undo a commit (file changes preserved, index changes are rolled back)
git reset HEAD^
# undo a commit (file changes and index changes rolled back)
git reset --hard HEAD^
@mungomash
mungomash / gist:1575536
Created January 7, 2012 18:14
Octopress cheat sheet
# create a new post
rake new_post["title"]
# re-build the site including any recent changes
rake generate
# run WEBrick server locally on port 4000
rake preview
# push changes to github (master branch)
@mungomash
mungomash / gist:1575274
Created January 7, 2012 16:46
MySQL command line cheat sheet
# create dump file from database
mysqldump wp_blog > 2012.1.7.mysql.dump.sql
# apply dump file to database wp_blog with user as root
mysql -u root wp_blog < 2012.1.7.mysql.dump.sql
@mungomash
mungomash / gist:1575248
Created January 7, 2012 16:42
MySQL monitor cheat sheet
-- create database
create database wp_blog;
-- create user
create user uwp_blog@localhost identified by 'pass123';
-- grant access
grant all privileges on wp_blog.* to uwp_blog@localhost;
-- list databases user has access to
@mungomash
mungomash / gist:1412790
Created December 1, 2011 02:06
Use curl to poll the Twitter API directly for a user's follower count.
function getTwitterFollowersCount($screen_name) {
$url = 'http://api.twitter.com/1/users/show.json?screen_name='.$screen_name;
$session = curl_init($url);
curl_setopt($session, CURLOPT_HEADER, false);
curl_setopt($session, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($session);
curl_close($session);
$user = json_decode($response);
return $user->followers_count;
}