Skip to content

Instantly share code, notes, and snippets.

View pwnall's full-sized avatar
🎯
Currently focused on the needs of Fuchsia

Victor Costan pwnall

🎯
Currently focused on the needs of Fuchsia
View GitHub Profile
### Keybase proof
I hereby claim:
* I am pwnall on github.
* I am pwnall (https://keybase.io/pwnall) on keybase.
* I have a public key whose fingerprint is 1CC4 CD57 EF01 392D 1DDF 2531 0C58 7774 D23E 223B
To claim this, I am signing this object:
def no_repeats(year_start, year_end)
no_repeats=[]
(year_start..year_end).each do |yr|
no_repeats<<yr if no_repeat?(yr)
end
no_repeats
end
def no_repeat?(year)
num_seen=[]
@pwnall
pwnall / puzzle.txt
Last active August 29, 2015 14:07
Quick and dirty Sudoku solver
x x x 4 x 6 x x x
x 5 6 x x x 3 9 x
x 9 x x x x x 4 x
2 x x x 3 x x x 1
x x x 6 x 9 x x x
3 x x x 5 x x x 6
x 4 x x x x x 5 x
x 8 2 x x x 4 7 x
x x x 5 x 2 x x x
# Backs up all the photos from Google Picasa Web Albums.
#
# The script downloads the original version of the photos, and is not limited to
# 1600x1200 thumbnails.
#
# Author:: Victor Costan
# Copyright:: Copyright (C) 2010 Victor Costan
# License:: MIT
require 'yaml'
#!/usr/bin/ruby
# Prints the number of cores on your system.
# Requires the ohai rubygem.
require 'rubygems'
require 'ohai'
ohai = Ohai::System.new
ohai.all_plugins
# Wraps an OAuth2 access token for Facebook.
class FacebookToken < ActiveRecord::Base
# The user whose token this is.
belongs_to :user
validates :user, :presence => true
# A unique ID on the Facebook site for the user owning this token.
validates :external_uid, :length => 1..32, :presence => true
# The OAuth2 access token.
@pwnall
pwnall / gist:2519877
Created April 28, 2012 15:42
Multiple HTTP requests in a single Rails controller action

Whenever users sign into my application, or access its homepage, I check to see if I have recent Facebook data for them. If not, I synchronously fetch the data from Facebook. I'd do it asynchronously, but I don't want to add logic for rendering the homepage with incomplete information.

The controller code is the if statement that starts here: https://github.com/pwnall/mit_hack_2012/blob/master/app/controllers/session_controller.rb#L17

Facebook data is cached in the Profile model (each user has a profile), and in the UserFriendship model.

The model code that does the fetches is here: https://github.com/pwnall/mit_hack_2012/blob/master/app/models/profile.rb#L38

The code calls some code in the fbgraph gem to fetch profile information. It also calls the method below, which uses curl to follow redirects:

@pwnall
pwnall / build_coffeescript.sh
Created June 29, 2012 11:22
Builder for encap packages for Ruby, the Sass compiler, Node.js and the CoffeeScript compiler
#### node-coffeescript-1.3.3 encap package
## Requires: nodejs-0.8.0
## Set up the encap cage.
# NOTE: this dance ensures that the build process is properly contained
sudo mkdir /usr/local/encap/node-coffeescript-1.3.3
sudo chown $USER:$USER /usr/local/encap/node-coffeescript-1.3.3
## Build and install in the encap cage.
@pwnall
pwnall / config.log
Created August 11, 2012 05:17
config.log after attempting to install Inkscape
This file contains any messages produced by compilers while
running configure, to aid debugging if configure makes a mistake.
It was created by inkscape configure 0.48.3.1, which was
generated by GNU Autoconf 2.68. Invocation command line was
$ ./configure --disable-dependency-tracking --enable-lcms --disable-poppler-cairo --prefix=/usr/local/Cellar/inkscape/0.48.3.1
## --------- ##
## Platform. ##
@pwnall
pwnall / Gemfile
Created October 18, 2012 19:47
Grader sample code
source :rubygems
gem 'sinatra', '>= 1.3.1', require: 'sinatra/base'
gem 'shotgun', '>= 0.9'
gem 'thin', '>= 1.3.1'