Skip to content

Instantly share code, notes, and snippets.

View btucker's full-sized avatar
👋

Ben Tucker btucker

👋
View GitHub Profile
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"/>
<title>forEach vs. map</title>
<script src="https://cdnjs.cloudflare.com/ajax/libs/benchmark/1.0.0/benchmark.min.js"></script>
<script src="./suite.js"></script>
</head>
<body>
<h1>Open the console to view the results</h1>

I need a way to write WebSocket client code that runs on a server in Node.js.

What it must do: Exactly what this browser-based app does, only running on a server, without the UI stuff.

https://github.com/scripting/1999client/blob/master/code.js#L133

It would make so much sense if Node implemented exactly the browser API for WebSockets, native. So much of Node works that way. But this is one of those times when it doesn't.

There are a few toolkits that do WebSockets on the server. But there isn't simple clean sample code that I've been able to convert to this application. I tried! :-)

@btucker
btucker / gist:d0b737170fbb759a129d
Created May 22, 2014 12:08
Overriding humanization of a particular ActiveRecord column
def self.human_attribute_name(col, options={})
col = case col.to_s
when "address"
"email address"
else
col
end
super(col, options)
end

Keybase proof

I hereby claim:

  • I am btucker on github.
  • I am btucker (https://keybase.io/btucker) on keybase.
  • I have a public key whose fingerprint is FDE0 4E59 2DFA C6FC 37DC 08B2 D671 1E5F E0CE 45FB

To claim this, I am signing this object:

@btucker
btucker / gist:5909226
Created July 2, 2013 13:18
Two rows per item in angular.
<table>
<tr><td>Number</td><td>Price</td><tr>
<tbody ng-repeat="order in orders">
<tr><td>{{order.description}}</td></tr>
<tr>
<td>{{order.number}}</td>
<td>{{order.price}}</td>
</tr>
</tbody>
</table>
@btucker
btucker / _.md
Created May 5, 2013 18:06
interactive areas
@btucker
btucker / gist:4506704
Last active December 10, 2015 23:08
dscourse <-> CANLEAD LTI
<form action='http://example.com/shiva/lti/receive.php' encType='application/x-www-form-urlencoded'>
<input name="oauth_consumer_key" type="hidden" value="key" />
<input name="oauth_signature_method" type="hidden" value="HMAC-SHA1" />
<input name="oauth_timestamp" type="hidden" value="1357860362" />
<input name="oauth_nonce" type="hidden" value="bwXOUxuuT2FV2VZ8EIbPqu7TwVetdgXigF30JmoPXrs" />
<input name="oauth_version" type="hidden" value="1.0" />
<input name="context_id" type="hidden" value="13" />
<input name="context_title" type="hidden" value=" Middle School Math (Master)" />
<input name="launch_presentation_return_url" type="hidden" value="http://uva-canlead.dev/modules/13" />
<input name="lis_person_contact_email_primary" type="hidden" value="ben@btucker.net" />
@btucker
btucker / gist:1356347
Created November 10, 2011 21:48
rails 2.3.x-esque remote_form_for in rails 3
<%= form_tag action_path, :id => 'remote_form', :remote => true do %>
<%= submit_tag %>
<% end %>
<div id="result"></div>
<%= javascript_tag do %>
jQuery(function($) {
$("#remote_form").bind("ajax:success", function(ev, data) {
$("#result").html(data);
@btucker
btucker / cache.rb
Created March 26, 2010 19:25
Memcached action caching for Sinatra (doesn't work in sinatra >= 1.0)
# Adds support for passing a :cache parameter to action definitions, eg:
#
# get '/state_map/?', :cache => 'state_map' do
# ...
# end
#
# :cache can also simply be passed true, in which case the route definition is used as the base
# key name. In all cases, any params are also included in the key.
#
# Author: ben tucker <ben@btucker.net>
#!/usr/bin/env ruby
require File.expand_path('../../config/environment', __FILE__)
how_many = 25000
my_class = Foo
my_class.delete_all
sc = my_class.create
my_class.benchmark "#{how_many} finds" do