Skip to content

Instantly share code, notes, and snippets.

@dsimard
dsimard / is a hash.js
Created January 6, 2011 19:39
How to know if an object is a hash
function isHash(obj) {
return typeof(obj) == "object" && Object.prototype.toString.call(obj) != "[object Array]";
}
@dsimard
dsimard / fixed.js
Last active December 4, 2018 19:24
Fixed decimals
(function fixed(float, decimal) {
decimal = decimal==undefined || decimal < 0 ? 2 : decimal;
return Math.round(float*Math.pow(10, decimal)).toString()
.replace((new RegExp("(\\d{"+decimal+"})$")), "$'.$1")
.replace(/^(-?)(\.)/, "$10.")
.replace(/^0$/, '0.00')
})(1.495)
@dsimard
dsimard / heroku_change_stack.sh
Created October 5, 2011 18:01
Update Heroku stack and change repository URL
# Create a new stack
heroku create --stack cedar
# it will reply something like this
# Creating stark-moon-1526... done, stack is cedar
# http://stark-moon-1526.herokuapp.com/ | git@heroku.com:stark-moon-1526.git
# Change repository URL
git remote set-url heroku git@heroku.com:stark-moon-1526.git
@dsimard
dsimard / heroku_node.js
Created December 22, 2011 18:59
Node.js on Heroku : "Process bound to port 3000, should be 12345"
var port = process.env.PORT || 3000;
app.listen(port);
@dsimard
dsimard / 2 levels deep.js
Created October 19, 2010 21:12
2 levels deep
var myApplication = {};
myApplication.instance = {
msg : "Hello world!",
hello : function() {
alert(myApplication.instance.msg);
}
}
@dsimard
dsimard / singletons in javascript.js
Created October 19, 2010 15:50
Real javascript singleton
var myApplication = {};
myApplication.instance = (function() {
var i = {
msg : "Hello world!",
hello : function() {
alert(i.msg);
}
};
@dsimard
dsimard / test.rb
Created January 3, 2016 20:08
Rails query object
begin
require 'bundler/inline'
rescue LoadError => e
$stderr.puts 'Bundler version 1.10 or later is required. Please update your Bundler'
raise e
end
gemfile(true) do
source 'https://rubygems.org'
gem 'rails', github: 'rails/rails'
@dsimard
dsimard / install weechat.sh
Created January 7, 2014 02:42
Install weechat
git clone git://git.sv.gnu.org/weechat.git
git checkout -b v0.4.2 v0.4.2
sudo apt-get install libncursesw5-dev libcurl4-gnutls-dev zlib1g-dev libgcrypt11-dev
mkdir build
cd build
cmake .. -DPREFIX=/path/to/weechat
make
make install
@dsimard
dsimard / ann.sql
Last active December 11, 2015 17:58
Kobo Glo Annotation
select book.contentid as bookid, book.title, b.bookmarkid, b.text, b.annotation
from bookmark b
inner join content c on b.contentid = c.contentid
inner join content book on c.bookid = book.contentid
order by book.datelastread desc, b.datecreated
@dsimard
dsimard / array.js
Created May 9, 2012 16:01
Why I love coffeescript
["The value of", property, "is", value].join(" ")