Skip to content

Instantly share code, notes, and snippets.

@kareemgrant
kareemgrant / Mongo console search
Created September 8, 2012 22:54
strings in custom _id from mongodb are being stripped off when the record is referenced in ruby
@kareemgrant
kareemgrant / prime number 10,001
Created October 19, 2012 00:06
Script that prints the 10,001st prime number
require 'mathn'
prime_array = []
TARGET = 10001
Prime.each do |prime|
if prime_array.size < TARGET
prime_array.push(prime)
else
break
@kareemgrant
kareemgrant / Rakefile
Created February 11, 2013 21:53
Event_manager testing exercise
require 'rake/testtask'
Rake::TestTask.new do |t|
t.pattern = "test/*_test.rb"
end
# RSpec 2.0 syntax Cheet Sheet by http://ApproachE.com
# defining spec within a module will automatically pick Player::MovieList as a 'subject' (see below)
module Player
describe MovieList, "with optional description" do
it "is pending example, so that you can write ones quickly"
it "is already working example that we want to suspend from failing temporarily" do
pending("working on another feature that temporarily breaks this one")
@kareemgrant
kareemgrant / Runline Activities json response
Created May 15, 2013 21:09
JSON response for Activity feed
[{"activity_date":"2012-10-10T19:09:29Z","activity_id":124069314,"activity_type":"Running","created_at":"2013-05-15T20:12:31Z","detail_present":true,"distance":10622.2704823343,"duration":3138.844,"id":1,"provider":"RunKeeper","run_detail":"---\n- timestamp: 0\n altitude: 51\n longitude: -77.044273\n latitude: 38.917912\n type: start\n- timestamp: 2.241\n altitude: 51\n longitude: -77.044273\n latitude: 38.917912\n type: gps\n- timestamp: 6.134\n altitude: 51\n longitude: -77.044295\n latitude: 38.917823\n type: gps\n- timestamp: 9.134\n altitude: 51\n longitude: -77.044271\n latitude: 38.917709\n type: gps\n- timestamp: 12.138\n altitude: 51\n longitude: -77.044229\n latitude: 38.917606\n type: gps\n- timestamp: 14.143\n altitude: 50.36363636363637\n longitude: -77.044154\n latitude: 38.917515\n type: gps\n- timestamp: 16.132\n altitude: 49.72727272727273\n longitude: -77.044095\n latitude: 38.91743\n type: gps\n- timestamp: 18.137\n altitude: 49.09090909090909\n longitude: -77.
@kareemgrant
kareemgrant / epoly.js
Created May 18, 2013 17:34
Preliminary route_builder code (still needs enhancement)
/*********************************************************************\
* *
* epolys.js by Mike Williams *
* *
* A Google Maps API Extension *
* *
* Adds various Methods to GPolygon and GPolyline *
* *
* .Contains(latlng) returns true is the poly contains the specified *
* GLatLng *
@kareemgrant
kareemgrant / activities_controller.rb
Created May 20, 2013 18:58
Displaying routes (polylines on a map) - this code uses the gon gem to pass data to javascript
class ActivitiesController < ApplicationController
def show
@activity = Activity.find_by_activity_id(params[:id])
path = @activity.run_detail["path"]
gon.stuff = path
render :layout => 'map'
end
end
@kareemgrant
kareemgrant / location_finder.html
Created May 21, 2013 23:52
example of geocode form for google maps
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>Google Maps API Example: Simple Geocoding</title>
<script src="http://maps.google.com/maps?file=api&amp;v=2&amp;sensor=false&amp;key=AIzaSyBsmTCDQYlmID4H8rqVe7Gb9Nm_SMpHahA" type="text/javascript"></script>
<script type="text/javascript">
var map = null;
var geocoder = null;
@kareemgrant
kareemgrant / heroes.rb
Created May 30, 2013 23:56
Graphing example with Neo4j
require 'rubygems'
require 'neography'
def create_hero(name)
Neography::Node.create(name: name)
end
# Create heroes
wolverine = create_hero('Wolverine')
storm = create_hero('Storm')
=Navigating=
visit('/projects')
visit(post_comments_path(post))
=Clicking links and buttons=
click_link('id-of-link')
click_link('Link Text')
click_button('Save')
click('Link Text') # Click either a link or a button
click('Button Value')