Skip to content

Instantly share code, notes, and snippets.


Dylan Jhaveri dylanjha

  • Mux
  • San Francisco
View GitHub Profile
View gist:10234719
I copied this example which integrates
Then I tweaked this script: <script src="js/chessboard.js"></script>
I changed the addEvents function to only register mouse event handler for desktops because when I tested it on old android browsers, touchstart and mousedown events were both firing:
if (isTouchDevice() === true) {
boardEl.on('touchstart', '.' + CSS.square, touchstartSquare);
containerEl.on('touchstart', '.' + CSS.sparePieces + ' .' + CSS.piece,
//$(window).on('touchmove', touchmoveWindow); nad cutout
//$(window).on('touchend', touchendWindow); nad cutout
} else { // all the same mouse stuff that is in the default setup
View gist:11092135
View sti-perf-hax.rb
class MyBase < ActiveRecord::Base
def self.compute_type(type_name)
case type_name
when "MyBase"; MyBase
when "Foo"; Foo
when "Bar"; Bar
else super
wrs / DeviseJsonAdapter.rb
Created Dec 8, 2010
JSON-encoded error and redirect results for Devise controllers
View DeviseJsonAdapter.rb
# JSON-encoded error and redirect results for Devise controllers.
# This overrides an internal method of Devise, so be careful when updating Devise!
# Usage:
# class Users::RegistrationsController < Devise::RegistrationsController
# include DeviseJsonAdapter
# end
# devise_for :users, :controllers => { :registrations => "users/registrations" }
kenkeiter / text_extents.js
Created Jul 12, 2012
Resize text to fit a min/max.
View text_extents.js
$.fn.textExtents = function(options){
var spans = $('span:visible', this);
var heightMax = parseInt($(this).css('max-height'));
var widthMax = parseInt($(this).css('max-width'));
var fontSize = parseInt($(this).css('font-size')); /* max font size */
var textHeight = 0;
var textWidth = 0;
View jquery-ui-tabs-1.9.2-patch.js
//this is to patch a bug with the jquery.ui.tabs API
// it has to do with the <base href> tag in <head> and jquery.ui.tabs
// being smart about figuring out weather to AJAX a tab or not
;(function() {
var tabsInitialised = false;
var _tabs = $.fn.tabs;
var updateBaseHrefs = function() {
View gist:5223561
#!/usr/bin/env ruby
require 'em-proxy'
TARGET = ARGV[0] ? ARGV[0].to_sym : :mysql
puts "Starting proxy on port 4000."
puts "Passing requests port 4100 (mysql) and port 4200 (postgres). Responses are returned from #{TARGET}."
Proxy.start(:host => "", :port => 4000, :debug => true) do |conn|
@start =
@data ="")
dylanjha / super.rb
Last active Dec 17, 2015
verifying how Ruby inheritance works
View super.rb
# 2.0.0dev :175 > @three =
# => #<Three:0x007fad66054540>
# 2.0.0dev :176 > @three.my_method
# im in class three
# im in the module
# im in class two
# im in class one
# @three.my_method_2
# <Three:0x108ca55e0>
dylanjha / css3-mixins.css.scss
Last active Dec 19, 2015
A bunch of handy mixins for SASS. Who ever thought vendor prefixes were a good idea, anyway?
View css3-mixins.css.scss
// Border Radius
@mixin round($radius: 4px) {
-moz-border-radius: $radius;
-webkit-border-radius: $radius;
border-radius: $radius;
// Box Shadow
@mixin shadow($shadow1: 0 0 4px #0A0A0A, $shadow2:false, $shadow3:false, $shadow4:false, $shadow5:false) {
$params: $shadow1;
@if $shadow2
xaviershay / repro.rb
Created Jul 5, 2013
Unexpected behaviour defining Ruby classes anonymously.
View repro.rb
repro.rb:16:in `block in <main>': uninitialized constant B (NameError)
from repro.rb:13:in `initialize'
from repro.rb:13:in `new'
from repro.rb:13:in `<main>'