Skip to content

Instantly share code, notes, and snippets.


Myles Eftos madpilot

View GitHub Profile
View gist:7330189
The Problem: We have a WCF JSON API, that we need to make accessible from third-party sites (on IE7+), so JSON-P looks like a good solution.
Issue is, (what the .NET guy here has told me), each endpoint in the WCF router will need to be re-written (or added to) to handle GETs (We currently use GET, POST, and DELETE depending on the action). That sucks.
My idea: An IIS module (handler?) that intercepts JSON-P requests, and transforms the request to something the WCF router can handle, then pads the response. Basically transparent JSON-P padding around WCF.
Make sense? Does this exist already?
View private_methods.rb
class Foo
def this_fails
def this_works
puts bar
madpilot / haversize.rb
Created Mar 9, 2013
Ruby haversine - finds the distance between to long/lats. Can be used as a paramater for sort.
View haversize.rb
def haversine(x, y)
r = 6371
lat1 = x.latitude
lat2 = y.latitude
lon1 = x.longitude
lon2 = y.longitude
d_lat = (lat2 - lat1) * Math::PI / 180
d_lon = (lon2 - lon1) * Math::PI / 180
View gist:3824507
document.domain = '';
madpilot / span_delay.rb
Created Aug 4, 2012
A Metal app that looks for a timestamp on a form field, and makes sure it happened at least two seconds ago...
View span_delay.rb
# Allow the metal piece to run in isolation
require(File.dirname(__FILE__) + "/../../config/environment") unless defined?(Rails)
class SpamDelay
@request =
if env["PATH_INFO"] =~ /^\/contact/
if env['REQUEST_METHOD'] == 'POST'
if @request.params['t'] && @request.params['t'].to_i < - 2
madpilot / response.html
Created May 23, 2012
Responsive images idea
View response.html
<!DOCTYPE html>
<script type="text/javascript" src=""></script>
<script type="text/javascript">
var resize = function() {
$('altimg').each(function(i, e) {
if($(e).css('display') != "none") {
$('img[data-name=' + $(e).attr('data-name') + ']').attr('src', $(e).attr('src')).attr('alt', $(e).attr('alt'));
madpilot / gist:2413866
Created Apr 18, 2012
How to select values from a select box
View gist:2413866
var el = document.getElementById('users');
el.onchange = function() {
document.getElementById('cdm').innerHTML = el.values[el.selectedIndex];
View gist:2205869
class MyClass
def my_method(param)
puts "this is my method #{param}"
my_class =
x = my_class.method :my_method
View gist:1969946
var results = JSON.parse(response.responseText);
// Strip out the head node
var list = new WinJS.Binding.List();
for (var i = 0, len = results.length; i < len; i++) {
// This throws: JavaScript runtime error: Object doesn't support property or method 'createListBinding'
companiesList.winControl.itemDataSource = list;
View gist:1715865, 'db', 'localization', 'GeoLiteCity.dat')).city(request.remote_ip)
=> ["", "", "AU", "AUS", "Australia", "OC", "08", "Perth", "", -31.9333, 115.8333]