Skip to content

Instantly share code, notes, and snippets.

// a simple custom wrapper
var Widget = new Class(Element, {
initialize: function(raw_element) {
// calling the Element's constructor
this.$super(raw_element, {
'class': 'my-widget'
});
},
// some other custom methods
@kaievns
kaievns / gist:758876
Created December 29, 2010 18:47
IE < 9 check
function is_IE8_or_less() {
try {
document.createElement('<input/>');
// IE8 or less
return true;
} catch(e) {
// IE9 or a W3C browser
return false;
}
}
sudo -s
gem install rubygems-update -v 1.3.7
gem uninstall rubygems-update -v 1.5.0
update_rubygems
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN">
<html lang="en">
<head>
<title>Draggable Issue</title>
<script type="text/javascript" src="http://cdn.rightjs.org/right.js"></script>
<script type="text/javascript" src="http://cdn.rightjs.org/plugins/dnd.js"></script>
</head>
<body>
<div style="margin: 10px auto;max-width:1180px;position:relative;height:710px;clear:both;overflow:scroll;background-color:grey">
<div rel="draggable" style="position: absolute; right: 0; background-color: green; width: 100px; height: 100px"></div>
@kaievns
kaievns / gist:908025
Created April 7, 2011 15:38
Jasmine Hack
// hacking jasmine over
var jasmine = require('jasmine-node');
var original_it = it;
var original_expect = expect;
var original_describe = describe;
global.it = function(desc, callback) {
if (typeof(desc) !== 'string') {
for (var key in desc) {
@kaievns
kaievns / gist:996893
Created May 28, 2011 14:20
Cubic Bezier function emulator
/**
* Cubic Bezier CSS3 transitions emulator
*
* See this post for more details
* http://st-on-it.blogspot.com/2011/05/calculating-cubic-bezier-function.html
*
* Copyright (C) 2011 Nikolay Nemshilov
*/
function Bezier(p1,p2,p3,p4) {
// defining the bezier functions in the polynomial form
@kaievns
kaievns / gist:1063414
Created July 4, 2011 14:43
Recursive Object -> Query String in CoffeeScript
#
# Recursively converts an object into a query string
#
to_query_string = (data)->
map = (hash, prefix='')->
result = []
for key, value of hash
key = if prefix is '' then key else "#{prefix}[#{key}]"
@kaievns
kaievns / gist:1200232
Created September 7, 2011 10:28
RJS substitute for right-rails
#
# RJS handler was kicked out of Rails 3.1 along with Prototype
# so, here is a little substitute coz we use it here and there
#
# Just save it in some file in the `config/initializers`
#
module ActionView
module Template::Handlers
class RJS
# Default format used by RJS.
@kaievns
kaievns / gist:1439065
Created December 6, 2011 17:27
RSpec speed up for BCrypt
#
# Making BCrypt to use minimal cost so that the specs run faster
#
# place this in the spec/support/bcrypt.rb file
#
require 'bcrypt'
module BCrypt
class Engine
class << self
@kaievns
kaievns / gist:1466051
Created December 12, 2011 08:59
MongoID counter_cache hack
#
# Save this in `lib/mongoid/counter_cache.rb`
#
# Then define your relations kinda like that
#
# class Comment
# belongs_to :post, counter_cache: true # 'comments_count'
# belongs_to :user, counter_cache: 'my_field_name'
# end
#