Skip to content

Instantly share code, notes, and snippets.

View mojowen's full-sized avatar
🍕
🤔

Scott Duncombe mojowen

🍕
🤔
View GitHub Profile
@mojowen
mojowen / preload_facebook_share_img.rb
Created October 11, 2016 21:33
The Facebook Sharer will not show a share image if the image is kind of large - this ruby function requests to share a URL programmatically so when a real users attempts to share the image will appear.
require 'rest-client'
def clear_url(url)
cookie = "" # Load facebook and copy and paste your session detail in here
cookie = Hash[ cookie.split('; ').map { |line| line.split('=') } ]
resp = RestClient.get "https://www.facebook.com/sharer/sharer.php?u=#{url}", { cookies: cookie }
raise 'whoops' if resp.code != 200
@mojowen
mojowen / lead_details.json
Last active October 5, 2016 20:06 — forked from sfletche/lead_details.json
JSON response to a specific lead
{
"id": "00Q22000001GZsGEAW",
"status": null,
"lead_contact": {
"name": "test Test",
"phone": null,
"email": null
},
"archived": null,
"expire_at": null,
@mojowen
mojowen / README.md
Last active October 3, 2016 18:11
Can You Vote?
@mojowen
mojowen / lead_dist_reducer_actions
Last active October 5, 2016 16:46 — forked from DTwigs/lead_dist_reducer_actions
Leads Reducer Actions and APi Calls
Leads Actions:
------------
GetLeads (URL: /locations/:location_id/leads?filter=<active|archived>)
------------
GetLead (URL: /locations/:location_id/leads/:lead_id)
@mojowen
mojowen / no_genius.html
Created March 28, 2016 16:48
Add to your blog or website to prevent your site from being viewed on genius.it
<script type="text/javascript">
(function(doc) {
var flat = doc.location.toString()
if( flat.match(/genius\.it/) !== null ) document.location = flat.split('genius.it').join('/')
})(document)
</script>
@mojowen
mojowen / byebye_itunes.sh
Last active March 28, 2016 16:53
Remove iTunes and prevent it from reinstalling it
#!/usr/bin/env bash
sudo rm -rf /Applications/iTunes.app
sudo echo "BAD APPLE! NO" > /Applications/iTunes.app
sudo chmod 000 /Applications/iTunes.app
sudo chflags uchg /Applications/iTunes.app
@mojowen
mojowen / load.sh
Last active March 18, 2016 22:39
Load ENV file into
#!/usr/bin/env bash
# Use on .env files, structured as KEY=VALUE. Will load into bash env
# Must be called with $ . load.sh
ENV_FILE=${1:-'./.env'}
cat $ENV_FILE | awk -F"=" '{print "Loading " $1}'
declare -a $(cat $ENV_FILE | awk -F"=" '{print $1"="$2}')
@mojowen
mojowen / bundle_all.sh
Created March 1, 2016 20:14
Install all the bundle dependencies in all the subdirectories
find . -maxdepth 1 -type d -exec bash -c "(source ~/.bash_profile && cd {} && echo {} && bundle install)" \;
@mojowen
mojowen / README.md
Last active December 2, 2018 10:54
Solution to the XKCD cartoon (http://xkcd.com/287/) NP-Complete.

I beefed an interview with AirBNB last week when my interviewee asked me to solve the NP-Complete problem described in this XKCD comic.

I got in my head almost immediately and got lost trying to design a recursive solution - instead attempting to iterate over the possibilities and then sub-iterate over a smaller set while keeping track of price.

Clear of the interview by a few days (and with a rejection letter in the inbox 😎) I wanted to try the problem again - starting from the very basic question: what are all the possible combinations of a N lengthed array of i length?

In the simplest form - how many 3-letter combinations can be produced from ['a', 'b', 'c']?

def possibilities(options, steps, prefix=nil)
@mojowen
mojowen / import_legacy_pipeline_stat.rb
Created June 18, 2015 00:09
Imports a CSV table of legacy stats
require 'csv'
raw = CSV.read('/tmp/pipeline_stat_table.csv')
labels = raw.shift
labels.delete('sample_id')
labels.delete('index')
data = raw.map{ |row| better = {}; labels.each_with_index{|k,i| v = row[i+2]; better[k] = v.index('.').nil? ? v.to_i : v.to_f }; [row.second, better] }
data.each{ |row| sample = Sample.find_by(name: row[0]); result = sample ? sample.results.first : nil; result ? (result.pipeline_metrics.update(row.second); result.save) : '' }