Skip to content

Instantly share code, notes, and snippets.

View maxwellE's full-sized avatar
🤔

Maxwell Elliott maxwellE

🤔
View GitHub Profile
@maxwellE
maxwellE / gumroad_oauth.rb
Created December 9, 2013 23:33
Gumroad OAuth2 sample code, uses the OAuth2 Gem https://github.com/intridea/oauth2
require 'oauth2'
client = OAuth2::Client.new('client_id', 'client_secret', :site => 'https://example.org')
client.auth_code.authorize_url(:redirect_uri => 'http://localhost:8080/oauth2/callback')
# => "https://example.org/oauth/authorization?response_type=code&client_id=client_id&redirect_uri=http://localhost:8080/oauth2/callback"
token = client.auth_code.get_token('authorization_code_value', :redirect_uri => 'http://localhost:8080/oauth2/callback', :headers => {'Authorization' => 'Basic some_password'})
response = token.get('/api/resource', :params => { 'query_foo' => 'bar' })
response.class.name
# => OAuth2::Response
namespace :generate do
desc 'Generate FLMS views in host app for additional styling'
task :views do
host_view_dir = File.expand_path("../../../app/views/flms/*", __FILE__)
unless Dir.exists?("app/views/flms")
FileUtils.mkdir "app/views/flms"
FileUtils.cp_r Dir[host_view_dir], "app/views/flms/"
end
end
end
@maxwellE
maxwellE / Euler.hs
Created May 20, 2013 02:38
Haskell List Monad Example
import Control.Monad
import Data.List
import Primes
primes4 = takeWhile (<10000) $ dropWhile (<1000) primes
result = do
a <- primes4
b <- dropWhile (<= a) primes4
guard ((sort $ show a) == (sort $ show b))
@maxwellE
maxwellE / async_json.java
Created April 2, 2013 18:02
Code for loading red lights needs to be in an async task bc we are using json http request
public void executeAsyncGet(View view) {
AsyncHttpClient client = new AsyncHttpClient();
RequestParams params = new RequestParams();
params.put("latitude", "40.192512");
params.put("longitude", "-83.526306");
params.put("distance_in_miles", "10000");
client.get("http://redlights.herokuapp.com/in_proximity_of",params ,new JsonHttpResponseHandler() {
@Override
public void onSuccess(JSONArray red_lights) {
for (int i = 0; i < red_lights.length(); i++) {
@maxwellE
maxwellE / fizz_buzz.rb
Last active December 14, 2015 12:39
FizzBuzz example implementation
class FizzBuzz
def initialize(lower_bound,upper_bound)
@lower_bound = lower_bound
@upper_bound = upper_bound
end
def evaluate
(@lower_bound..@upper_bound).map do |x|
if (x % 5) == 0 && (x % 3) == 0
"FizzBuzz"
elsif (x % 5) == 0
import com.github.kevinsawicki.http.HttpRequest;
public class HTTPCaller {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
@maxwellE
maxwellE / template_ex.js
Created February 26, 2013 00:03
example for jia
// ajax call
req = $.get('/get_assets',{company_id: $(this).dataset.company});
req.success(function(data){
JST['template name']
assets: data
})
//template call
<img src="{{it.assets.pic1}}"<img>
@maxwellE
maxwellE / primes.rb
Created December 15, 2012 01:21
Calculating Primes in Ruby
def isPrimeRegexp n
"1" * n =~ /^1?$|^(11+?)\1+$/
end
@maxwellE
maxwellE / mt1.md
Created December 10, 2012 03:52
mt1 sol

I am still working on grading the midterms and hope to be done before class. In the meantime, here are some detailed comments on individual questions, based on what I have seen so far; sorry, I have not proofread these comments so there may be mistakes/typos:

  1. This was about the use of intermediate languages in compilers and interpreters. Many got parts of this wrong. For example, using int. lang. doesn't improve efficiency; it can even reduce it (because of compiling in two stages rather than directly to machine language).
@maxwellE
maxwellE / mt2.md
Created December 10, 2012 03:53
mt2

I am still working on grading the midterms and hope to be done before class. In the meantime, here are some detailed comments on individual questions, based on what I have seen so far: [I haven't proofread this, sorry for any typos]:

  1. This was about type errors being caught more easily in the OO approach. Most people got this. The point is that since nodes that are instances of a given non-terminal are represented as objects that are instances of the corresponding class, there being one class for