Skip to content

Instantly share code, notes, and snippets.

ActiveResource/Rails confuses parameter values when deserializing.
Using ActiveResource 2.3.8 (AccountUpdate is ActiveResource class) with ruby 1.8.7.
The REST server is a Rails 3.0.0beta4 running ruby 1.9.2.
Set up two hashes, one containing an _id value, the other not. The Hash with the
_id field has a :name value of "hello", the other hash contains only the :name field
with value fubar.
=============
Something that happened to me the other day -- rounding on the 5th value after the decimal point.
Ruby code that was tested:
puts "%.2f" % 1.234
puts "%.2f" % 1.235
puts "%.4f" % 1.23523
puts "%.4f" % 1.23525
The last value should be 1.2353 (at least that is what i learnt in my maths classes)
div
&.spinner
position: relative
width: 100px
height: 100px
display: inline-block
div
width: 12%
height: 26%
background: #000
@gorenje
gorenje / gist:809276
Created February 3, 2011 09:44
rvm & git in bash prompt
function rvm_version {
if [ -x ~/.rvm/bin/rvm-prompt ] ; then
echo $(~/.rvm/bin/rvm-prompt)
else
echo " - no rvm - "
fi
}
function parse_git_branch {
ref=$(git symbolic-ref HEAD 2> /dev/null) || return
@gorenje
gorenje / gist:809292
Created February 3, 2011 09:55
cd-alias-add bash command
ALIAS_FILE_CDS=~/.bash_aliases_cd
function _funct_cd_alias_add
{
local name=$1
name=$(echo $name | sed s/^cd-//) # remove any leading cd- (we'll add that)
local varname=$(echo $name | sed s/-/_/g) # replace minus with underscore
shift
local directory=$* # can't do replace on $* value directly -- man bash for more
if [ "$directory" == "" ]; then
@gorenje
gorenje / gist:809293
Created February 3, 2011 09:56
find-rails bash alias
function _funct_find_rails
{
local app=""
local option=
local what=$*
OPTIND=1
while getopts "a:es:" option
do
case $option in
e)
@gorenje
gorenje / gist:809297
Created February 3, 2011 10:02
dbctl
function _funct_dbctl {
local action dbname logfile cmd
action=$1 ; shift ; dbname=$1 ; logfile=""
case $dbname in
mysql)
dbname="org.macports.mysql5"
;;
mongo)
echo "launchctl load /opt/local/etc/LaunchDaemons/org.macports.mongodb" | sudo bash 2>/dev/null
@gorenje
gorenje / gist:809327
Created February 3, 2011 10:35
Jake extensions
var XibsToConvert = ["FlickrWindow", "FacebookWindow", "TwitterWindow",
"YouTubeWindow", "LinkTEProperties", "HighlightTEProperties",
"ImageTEProperties", "TwitterFeedTEProperties","TextTEProperties"];
task( "nibs", function()
{
// Tried using JAKE.file but that didn't not want to work with subdirectories,
// i.e. Resources/
for ( var idx = 0; idx < XibsToConvert.length; idx++ ) {
var filenameXib = "Resources/../Xibs/" + XibsToConvert[idx] + ".xib";
@gorenje
gorenje / dhcpd-config-mode.el
Created February 8, 2011 21:47
syntax highlight for dhcpd configuration files.
(define-derived-mode dhcp-mode
c-mode "DHCP config"
"Major mode for DHCP configuration files.
\\{dhcp-mode-map}"
(setq case-fold-search nil))
(defvar dhcpdGroupDecl-keywords
'("group" "shared-network" "subnet" "host" "pool" "failover"
"class" "subclass" "key" "zone" "logging" "channel" "netmask")
"DHCP group declaration keywords.")
@gorenje
gorenje / MixinTest.j
Created February 9, 2011 10:33
An example of how to define "Mixin Classes" that can be mixed into existing classes. Useful for avoiding ever longer inheritence chains.
/*
* Provide a simple mixin helper to extend classes without inheritence. At the same
* time, this demostrates various scenarios when using mixins.
*
* For more information, check out (branch URL - release 0.8.1 of cappuccino)
* https://github.com/280north/cappuccino/blob/release-0.8.1/Objective-J/Runtime.js
* Note: this code is base on version 0.8.1 of Cappuccino.
*
* Install OJTest framework (https://github.com/280north/OJTest/wiki) and this class
* can be called: