Skip to content

Instantly share code, notes, and snippets.

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:

$stack, $draws = [], {}
def method_missing *args
return if args[0][/^to_/]
$stack << args.map { |a| a or $stack.pop }
$draws[$stack.pop(2)[0][0]] = args[1] if args[0] == :<
end
class Array
def +@
@Stephenitis
Stephenitis / gist:5538949
Created May 8, 2013 08:04
self join many to many
<?xml version="1.0" encoding="utf-8" ?>
<!-- SQL XML created by WWW SQL Designer, http://code.google.com/p/wwwsqldesigner/ -->
<!-- Active URL: http://socrates.devbootcamp.com/sql -->
<sql>
<datatypes db="mysql">
<group label="Numeric" color="rgb(238,238,170)">
<type label="Integer" length="0" sql="INTEGER" re="INT" quote=""/>
<type label="Decimal" length="1" sql="DECIMAL" re="DEC" quote=""/>
<type label="Single precision" length="0" sql="FLOAT" quote=""/>
<type label="Double precision" length="0" sql="DOUBLE" re="DOUBLE" quote=""/>