Skip to content

Instantly share code, notes, and snippets.

@Stephenitis
Stephenitis / mongo_replica_member_status_check.js
Created February 24, 2016 18:00
This script polls the rs.status() to check for the state of the various replica sets.
MAXSCRIPT_RUN_ITERATIONS = 1800 // approximately 30 minutes
for (var i = 0; i < MAXSCRIPT_RUN_ITERATIONS; i++) {
sleep(1000);
var currentdate = new Date();
var datetime = new Date().toLocaleString();
var rsStatus = rs.status()
var members = rsStatus.members
// Change this index depending on the # of members in your set
@Stephenitis
Stephenitis / hash_that_wont_encode.rb
Created December 26, 2013 19:05
this Json returns a error when trying to encode with JSON or MultiJSON
{"Stamford, Connecticut"=>["Stamford firefighter Nick Tamburro pays his respects outside the home of Madonna Badger in Stamford, Conn., Tuesday, Dec. 27, 2011.", "(JTA) - The nephew of Connecticut Gov. Dannel Malloy was arrested for trespassing in a yeshiva high school in Stamford. Kerry Mallory, an actor who appears in the new movie “The Wolf of Wall Street,” was arrested Monday on the property of Yeshiva Bais ...", "Jennifer Oxer of DeYulio Sausage holds eviction notice on Friday December 20, 2013 in the Stamford, Conn. office. The business is getting evicted on Monday forcing the furlough of 20 employees right before Christmas as the city looks to move ahead with ...", "Reporter Christina Chiarelli takes a look back at who made news in Culture in Stamford in 2013. A nine year veteran with the Stamford Police Department and leader of its K-9 unit -- Officer Seth O'Brien was named Officer of the Year.", "Four candidates stepped up for the city's top job after Republican Michael Pavia decided not to run for r
iced@iced test % cat test.worker
exec 'test.rb'
iced@iced test % cat test.rb
puts config.inspect
puts "YO!"
iced@iced test % iron_worker upload test --worker-config test.json
------> Creating client
Project 'Test' with id='517baf16ed3d7607990013a0'
------> Creating code package
Found workerfile with path='test.worker'
{"push_type":"multicast/unicast",
"subscribers": [
{"url": "http://thiswebsitewillthrowanerror.com"}
],
"error_queue": "MY_EXAMPLE_ERROR_QUEUE"}
{"push_type":"multicast/unicast",
"subscribers": [
{"url": "http://thiswebsitewillthrowanerror.com"}
],
"error_queue": "MY_EXAMPLE_ERROR_QUEUE"}
# Median of an array of numbers
def median(array)
array.each do |element|
if (array.length/2).to_f == (array.length.to_f)/2
element_even = element.to_i
median_value = (element_even[(array.length/2)].to_f + element_even[(array.length/2) + 1].to_f) / 2
else
element_odd = element.to_i
median_value = element_odd[(array.length/2) + 1].to_i
@Stephenitis
Stephenitis / point_inside_a_triangle.rb
Last active December 19, 2015 13:29
find a point within a triangle
#Stephen Nguyen - July 10
# drew a point within a triangle and realized that the point within the
# triangle makes 3 smaller triangles whose area is equal to the area of the triangle
# if outside the triangle the area will always be greater than the the area of the triangle
# method will calculate the area of three points by inputting the length of the 3 triangle sides into heron's formula
# heron's formula was looked up to complete this http://matrixpp.blogspot.com/2012/11/herons-formula.html
def area(point_1, point_2, point_3)
side_1 = Math.hypot(point_2[0]-point_1[0], point_2[1]-point_1[1])
@Stephenitis
Stephenitis / brokenup.html
Last active December 18, 2015 17:59
Dissecting the Twitter embeddable widget.
<a class="twitter-timeline" href="https://twitter.com/Stephenitis" data-widget-id="347693875802042368">Tweets by @Stephenitis</a>
<script>
!function(doc,script,id){
var js,
fjs = doc.getElementsByTagName(script)[0],
// fjs = a script object
protocol = /^http:/.test(doc.location)?'http':'https';
// protocol = http or https
if( !doc.getElementById(id) ) {
js = doc.createElement(script);

GitHub OAuth Busy Developer's Guide

This is a quick guide to OAuth2 support in GitHub for developers. This is still experimental and could change at any moment. This Gist will serve as a living document until it becomes finalized at Develop.GitHub.com.

OAuth2 is a protocol that lets external apps request authorization to private details in your GitHub account without getting your password. All developers need to register their application before getting started.

Web Application Flow

  • Redirect to this link to request GitHub access:

jQuery and jQuery-ujs

When using Rails 3.0 and later we already get jquery-rails for free. Look in the gemfile and you'll see:

gem "jquery-rails"

You can view the full documentation here: source: https://github.com/indirect/jquery-rails

If you take a look in APP_DIR/app/assets/javascripts/application.js, you'll notice the following lines of code: