Skip to content

Instantly share code, notes, and snippets.

View JamesChevalier's full-sized avatar

James Chevalier JamesChevalier

View GitHub Profile
@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:7900a468a5038f7d0dc8
Created July 31, 2015 13:49
Key & Peele's East/West College Bowl Names
--- EAST ---
D'Marcus Williums
T.J. Juckson
T'varisuness King
Tyroil Smoochie-Wallace
D'Squarius Green, Jr.
Ibrahim Moizoos
Jackmerius Tacktheritrix
D'Isiah T. Billings-Clyde
@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: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'
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:6868539286a5c291522b
Created November 3, 2014 16:36
MailChimp signup in Ruby using mailchimp-api gem without double opt-in
require 'mailchimp'
mailchimp = Mailchimp::API.new(ENV['mailchimp_api_key'])
mailchimp.lists.subscribe(ENV['mailchimp_list_id'],
{ email: '[email protected]' },
{ 'FNAME' => 'First Name', 'LNAME' => 'Last Name' },
'html',
false)
# So the format is:
# mailchimp.lists.subscribe(list_id, { email: address }, { merge_vars }, 'email type', double_optin_boolean)

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:

@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)))
@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 / poly_to_osm.rb
Created February 8, 2014 00:35
This is my script to generate OSMs out of all of a country's POLY files.
#!/usr/bin/env ruby
Dir.glob('poly/*.poly').each_slice(50) do |group|
bp_wx = ''
group.each do |poly_file|
file = File.basename(poly_file, '.poly')
city, region = file.split('_')
bp_wx << "--buffer bufferCapacity=50000"\
" --bp file='poly/#{city}_#{region}.poly'"\