Skip to content

Instantly share code, notes, and snippets.

View JamesChevalier's full-sized avatar

James Chevalier JamesChevalier

View GitHub Profile
@JamesChevalier
JamesChevalier / osmosis_on_digitalocean.sh
Created February 8, 2014 00:13
My complete process of generating OSMs from POLYs on DigitalOcean servers
# Server
apt-get update
apt-get install -y python-software-properties
add-apt-repository -y ppa:webupd8team/java
apt-get update
apt-get install -y oracle-java7-installer sysstat convmv ruby1.9.3
wget http://bretth.dev.openstreetmap.org/osmosis-build/osmosis-latest.tgz
mkdir osmosis
tar -xvzf osmosis-latest.tgz -C osmosis
chmod a+x osmosis/bin/osmosis
@JamesChevalier
JamesChevalier / gist:906af3cfbc3a500ab59e
Created May 16, 2014 22:42
Refresh MapMyFitness token with HTTParty
response = HTTParty.post('https://oauth2-api.mapmyapi.com/v7.0/oauth2/access_token/',
body: { grant_type: 'refresh_token',
refresh_token: user.refresh_token,
client_id: MAPMYFITNESS_CLIENT_KEY,
client_secret: MAPMYFITNESS_CLIENT_SECRET },
headers: { 'Api-Key' => MAPMYFITNESS_CLIENT_KEY })
user.update_attributes!(access_token: response['access_token'], refresh_token: response['refresh_token'])
@JamesChevalier
JamesChevalier / gist:0337bc69f117b3518b92
Created June 9, 2014 18:52
Use Arel to run an AND and OR search
set_one_ids = [1,2]
set_two_ids = [3,4]
set_one_query = Thing.where(id: id_set_one).where_values.reduce(:and)
set_two_query = Thing.where(id: id_set_two).where_values.reduce(:and)
Thing.where(set_one.or(set_two))
# That runs the SQL:
# SELECT `things`.* FROM `things` WHERE ((`things`.`id` IN (1, 2) OR `things`.`id` IN (3, 4)))

Keybase proof

I hereby claim:

  • I am jameschevalier on github.
  • I am jameschevalier (https://keybase.io/jameschevalier) on keybase.
  • I have a public key whose fingerprint is 09FC 9A3C F705 17E5 3317 C898 CE60 730F F1EC 808D

To claim this, I am signing this object:

def self.circle_path(center, radius, complete_path = false)
# For increased accuracy, if your data is in a localized area, add the elevation in meters to r_e below:
r_e = 6378137.0
@@d2r ||= Math::PI/180
@@multipliers ||= begin
segments = 16
dRad = 2*Math::PI/segments
(segments + (complete_path ? 1 : 0)).times.map do |i|
rads = dRad*i
y = Math.sin(rads)
@JamesChevalier
JamesChevalier / gist:440acbc38f61d2a4ae15
Created May 23, 2015 15:02
Select published posts with their category name in a wordpress database - only these fields: title, content, date, and category name
SELECT DISTINCT wp_posts.post_title, wp_posts.post_content, wp_posts.post_date, wp_terms.name FROM wp_posts
LEFT JOIN wp_postmeta ON(wp_posts.ID = wp_postmeta.post_id)
LEFT JOIN wp_term_relationships ON(wp_posts.ID = wp_term_relationships.object_id)
LEFT JOIN wp_term_taxonomy ON(wp_term_relationships.term_taxonomy_id = wp_term_taxonomy.term_taxonomy_id)
LEFT JOIN wp_terms ON(wp_term_taxonomy.term_id = wp_terms.term_id)
WHERE wp_term_taxonomy.taxonomy = 'category'
AND wp_posts.post_status = 'publish'
AND wp_posts.post_type = 'post'
@JamesChevalier
JamesChevalier / strava_connection.rb
Created July 23, 2015 00:12
An example of how you could delete revoked Strava users, along with a primitive retry system
user = User.find(user_id)
begin
client = Strava::Api::V3::Client.new(access_token: user.token)
strava_user = client.retrieve_current_athlete
rescue => error
if error.message.include?('"errors":[{"resource":"Athlete","field":"access_token","code":"invalid"')
user.destroy and return
else
sleep 1
@JamesChevalier
JamesChevalier / gist:5c8bd1a7ac9f5bfbf4f3
Created August 9, 2015 22:39
MapMyFitness API Activity Types with IDs
[
["Generic", "1"],
["Workout", "2"],
["General", "3"],
["Fartleks", "7"],
["Indoor Sport / Other Activity", "8"],
["Walk", "9"],
["Winter Sport / Activity", "10"],
["Bike Ride", "11"],
["Gym Workout", "12"],
@JamesChevalier
JamesChevalier / gist:1221030
Last active September 27, 2015 05:48
dumbly simple debug output ... Just replace VARIABLENAME with the name (without the $) of the variable (probably an array) you want to see the contents of
// Begin Debug Output
echo "Debug Output for VARIABLENAME:<br><pre>";
var_dump($VARIABLENAME);
echo "</pre><br>End of debug output.";
// End Debug Output
@JamesChevalier
JamesChevalier / index.html
Created January 9, 2012 17:47
Zurb's Foundation (v2.1.4), with transparent divs & ToTop JS
<!DOCTYPE html>
<!-- paulirish.com/2008/conditional-stylesheets-vs-css-hacks-answer-neither/ -->
<!--[if lt IE 7]> <html class="no-js lt-ie9 lt-ie8 lt-ie7" lang="en"> <![endif]-->
<!--[if IE 7]> <html class="no-js lt-ie9 lt-ie8" lang="en"> <![endif]-->
<!--[if IE 8]> <html class="no-js lt-ie9" lang="en"> <![endif]-->
<!--[if gt IE 8]><!--> <html lang="en"> <!--<![endif]-->
<head>
<meta charset="utf-8" />