Skip to content

Instantly share code, notes, and snippets.

@danapplegate
danapplegate / about.md
Created August 10, 2011 18:08 — forked from jasonrudolph/about.md
Programming Achievements: How to Level Up as a Developer
@danapplegate
danapplegate / securing_rails_updates.md
Created March 5, 2012 20:29 — forked from peternixey/securing_rails_updates.md
How Homakov hacked GitHub and how to protect your application

##How Homakov hacked GitHub and the line of code that could have prevented it


Please note: THIS ARTICLE IS NOT WRITTEN BY THE GITHUB TEAM or in any way associated with them. It's simply hosted as a Gist because the markdown formatting is excellent and far clearer than anything I could manage on my personal Tumblr at peternixey.com.

If you'd like to follow me on twitter my handle is @peternixey


@danapplegate
danapplegate / gist:2853235
Created June 1, 2012 16:08
MySQL insert using double list comprehension
def reward_close(data):
fields = ['id','name','image_url','hint','message','type','allow_duplicates','active']
print "Processing %i rewards" % len(data)
c.executemany( """INSERT INTO `ford_post_season`.`bv_rewards` (`%s`) VALUES (%s)""" % ('`, `'.join(fields), ', '.join(['%s'] * len(fields))),
[[reward[field].encode('utf-8') if hasattr(reward[field], 'encode') else reward[field] for field in fields] for reward in data])
@danapplegate
danapplegate / .gitalias
Created November 14, 2012 04:49 — forked from rogeruiz/.gitalias
Git aliases that I find useful.
[alias]
co = checkout
ci = commit
st = status
br = branch
fall = fetch --all
mr = merge
unstage = reset HEAD
pl = pull
ps = push
@danapplegate
danapplegate / gist:6372974
Created August 29, 2013 00:18
Stack trace of version error between sinatra_auth_github and Octokit 2.0.0
NameError - uninitialized constant Octokit::Configuration:
/Users/applegatedt/.rvm/gems/ruby-1.9.3-p194@sinatra_auth_github/gems/warden-github-0.14.0/lib/warden/github/oauth.rb:62:in `build_uri'
/Users/applegatedt/.rvm/gems/ruby-1.9.3-p194@sinatra_auth_github/gems/warden-github-0.14.0/lib/warden/github/oauth.rb:27:in `authorize_uri'
/Users/applegatedt/.rvm/gems/ruby-1.9.3-p194@sinatra_auth_github/gems/warden-github-0.14.0/lib/warden/github/strategy.rb:48:in `begin_flow!'
/Users/applegatedt/.rvm/gems/ruby-1.9.3-p194@sinatra_auth_github/gems/warden-github-0.14.0/lib/warden/github/strategy.rb:25:in `authenticate!'
/Users/applegatedt/.rvm/gems/ruby-1.9.3-p194@sinatra_auth_github/gems/warden-1.2.3/lib/warden/strategies/base.rb:53:in `_run!'
/Users/applegatedt/.rvm/gems/ruby-1.9.3-p194@sinatra_auth_github/gems/warden-1.2.3/lib/warden/proxy.rb:354:in `block in _run_strategies_for'
/Users/applegatedt/.rvm/gems/ruby-1.9.3-p194@sinatra_auth_github/gems/warden-1.2.3/lib/warden/proxy.rb:349:in `each'
/Users/appl
@danapplegate
danapplegate / gist:98209b1eb2721ca7365c
Last active August 29, 2015 14:16
A description of the "userVote" type of problem, with proposed solutions including their drawbacks and advantages

The userVote Problem

We are struggling to find a way to efficiently and cleanly implement the following common use case in our code base:

  • There is an object that can be voted on
    • Project
    • Discussion
    • Comment
  • We have an array of these objects
  • We would like to know if a user has voted on each of these objects
  • We need to associate each of these Vote objects with its respective Project, Discussion or Comment, if it exists
  • Throughout our view hierarchy, we need easy access to these related Votes in the same locations that we need access to the associated Vote object, such that the pattern for accessing them is clear, simple to repeatedly implement, and preferable to any sort of "hacky" workaround solution. (Such as making $userVote a public property of the voted object, or defining a "shortcut" relation-that-is-not-a-relation to access the vote.)
@danapplegate
danapplegate / gist:8c516c280064c06b6b17
Last active August 29, 2015 14:16
Inverse relation using "through"

At several points in our code, we might do something similar to the following:

$parentClass = ParentClasses::model()->findOneByPk($parentClassId);
...
$sessions = $parentClass->sessions;
foreach ($sessions as $session) {
    // Do something with the parent class of the session, perhaps
    // rendering it in a subview
    $parentClass = $session->parentClass;
    echo $parentClass->title;
@danapplegate
danapplegate / Vagrantfile.rb
Last active September 14, 2015 22:54
Output of running vagrant up, for issue https://github.com/mitchellh/vagrant/issues/6267
base_path = 'htdocs/protected/config'
Vagrant::Config.run do |config|
config.vm.define :web, primary: true do |web_config|
web_config.vm.box = 'my_company'
web_config.vm.box_url = 'http://files.vagrantup.com/precise64.box'
web_config.vm.network :hostonly, '192.168.33.10'
<!DOCTYPE html>
<html>
<head>
<title>Tom Hanks - My favorite actor!</title>
</head>
<body>
<h1>Tom Hanks Fan Page!</h1>
<img src="http://www.thewrap.com/wp-content/uploads/2014/02/OscarWrap-Tom-Hanks.jpg">
<p>Tom Hanks is my favorite actor. He has had a long and impressive career playing everything from a boy trapped in an adult body in "Big", to a battle-hardened soldier in "Saving Private Ryan". I think my favorite part he played was as an AIDS patient in the critically-acclaimed movie "Philadelphia", for which he won both a Golden Globe and an Oscar. <a href="http://www.imdb.com/title/tt0107818/">Click here to learn more about "Philadelphia"</a>!</p>
<img src="http://farm4.static.flickr.com/3603/3475222867_193f5a8e16.jpg">
<!DOCTYPE html>
<html>
<head>
<title>Tom Hanks - My favorite actor!</title>
</head>
<body>
<h1>Tom Hanks Fan Page!</h1>
<img src="http://www.thewrap.com/wp-content/uploads/2014/02/OscarWrap-Tom-Hanks.jpg">
<h3>Why I love Tom Hanks</h3>
<p>Tom Hanks is my favorite actor. He has had a long and impressive career playing everything from a boy trapped in an adult body in "Big", to a battle-hardened soldier in "Saving Private Ryan". I think my favorite part he played was as an AIDS patient in the critically-acclaimed movie "Philadelphia", for which he won both a Golden Globe and an Oscar. <a href="http://www.imdb.com/title/tt0107818/">Click here to learn more about "Philadelphia"</a>!</p>