Skip to content

Instantly share code, notes, and snippets.

View DrewWeth's full-sized avatar

Drew Wetherington DrewWeth

View GitHub Profile
/*
Pretend like Strings are actually a thing
*/
typedef struct node{
String value;
Node* next;
} Node;
// Inserts to the front of the list
#define UNECESSARY_CONSTANT 0
typedef struct node {
String value;
typedef struct node next;
} Node;
/*
value_to_index[] = Hash(String value, int count)
index_to_ref[] = Hash(int count, Node* reference)
class Member < ActiveRecord::Base
has_many :members_in_orgs
has_many :orgs, :through => :members_in_orgs
end
class MembersInOrgs < ActiveRecord::Base
validates_uniqueness_of :member_id, scope: :org_id
belongs_to :orgs
belongs_to :members
end
class CreateMembersInOrgs < ActiveRecord::Migration
def change
create_table :members_in_orgs do |t|
t.integer :mio_id
t.integer :member_id
t.integer :org_id
t.timestamps
end
end
a = "123"
hash = { 1 => 'a',
2 => 'b',
3 => 'd'}
a = a.split('').each do |variable|
puts hash[variable.to_i]
end
//
// Disclamer:
// ----------
//
// This code will work only if you selected window, graphics and audio.
//
// Note that the "Run Script" build phase will copy the required frameworks
// or dylibs to your application bundle so you can execute it on any OS X
// computer.
@DrewWeth
DrewWeth / Sorry.js
Last active August 29, 2015 14:14
Hackathon Hackers Scraper (sorry)
// STEP 1: First import jQuery
// Here's a link to raw jQuery that can be copy/pasted into the console
// http://code.jquery.com/jquery-1.7.1.min.js
// NOTE: You have to have all the comments expanded first.
// STEP 2: copy/paste this. I'm not sure if #u_0_21 will work for everyone.
a = $('div > p:contains("Comment with your e-mail if you want $100")').parent().parent(); $('li div.UFICommentContent span.UFICommentBody', a).each(function(elem){ arr.push($(this).text()); });copy.log(arr);
@DrewWeth
DrewWeth / gist:b6a5ec907465b649d3cd
Last active August 29, 2015 14:22
HackerRank Stock Optimization
import java.lang.reflect.Array;
import java.util.ArrayList;
public class Main {
public Main(){
}
public static void main (String[]args){
# bin/phantomjs --webdriver=9999
require 'selenium-webdriver'
require 'nokogiri'
require 'uri'
require 'json'
# supply video ID or full YouTube URL from command line
arg = ARGV[0]
if arg =~ /^#{URI::regexp}$/
require 'open-uri'
require 'nokogiri'
starting_url = ARGV[0]
channel_ids=[]
video_urls=[]
temp=[]
url_string = ""
page_source = Nokogiri::HTML(open(starting_url))
page_source.css("a").each do |url|