Skip to content

Instantly share code, notes, and snippets.

View cyakimov's full-sized avatar
🏠
Working from home

Carlos Yakimov cyakimov

🏠
Working from home
  • Falabella
  • Santiago, Chile
View GitHub Profile
@cyakimov
cyakimov / gist:1007096
Created June 3, 2011 20:24
Array to Hash in Ruby
#Create a hash like {1=>2, 3=>4} from Array of values
arr = [1,2,3,4]
hash = Hash[*arr]
@cyakimov
cyakimov / gist:1019169
Created June 10, 2011 16:09
Filter empty strings and nils from array in Ruby
#["",nil,"something","another",123,""] => ["something","another",123]
array_to_filter.reject &:empty?
@cyakimov
cyakimov / visibility.js
Created June 20, 2011 16:01 — forked from niallkennedy/visibility.js
Page Visibility API visibility test using jQuery
var isVisible = false;
function onVisible() {
isVisible = true;
jQuery.getScript("http://www.google-analytics.com/ga.js");
}
if ( document.webkitVisibilityState === undefined || document.webkitVisibilityState === "visible" ) {
onVisible();
} else {
jQuery.bind( "webkitvisibilitychange", function() {
@cyakimov
cyakimov / gist:1049915
Created June 27, 2011 21:41
CentOS / Fedora 'build-essential' equivalent
yum groupinstall "Development Tools"
@cyakimov
cyakimov / description.txt
Created July 11, 2011 20:38 — forked from samueldana/description.txt
Server setup issue using Nginx, RVM, Ruby-1.9.1, and Thin
So, I'm setting up a new Ubuntu 10.04 server with nginx, RVM, Ruby-1.9.1, and Thin.
I got through installing nginx, RVM, ruby-1.9.1 without any problems.
Ruby-1.9.1 was installed using 'rvm install x';
I don't have a system Ruby (Which is what I've been doing previously).
I've also set the default ruby to 1.9.1 for myself and root.
I installed the thin gem using 'gem install thin'
I then installed thin to the system using
'thin install'
@cyakimov
cyakimov / gist:1139981
Created August 11, 2011 15:49
Decode Facebook signed_request with NodeJS
//npm install b64url
//A signed_request for testing:
//WGvK-mUKB_Utg0l8gSPvf6smzacp46977pTtcRx0puE.eyJhbGdvcml0aG0iOiJITUFDLVNIQTI1NiIsImV4cGlyZXMiOjEyOTI4MjEyMDAsImlzc3VlZF9hdCI6MTI5MjgxNDgyMCwib2F1dGhfdG9rZW4iOiIxNTI1NDk2ODQ3NzczMDJ8Mi5ZV2NxV2k2T0k0U0h4Y2JwTWJRaDdBX18uMzYwMC4xMjkyODIxMjAwLTcyMTU5OTQ3NnxQaDRmb2t6S1IyamozQWlxVldqNXp2cTBmeFEiLCJ1c2VyIjp7ImxvY2FsZSI6ImVuX0dCIiwiY291bnRyeSI6ImF1In0sInVzZXJfaWQiOiI3MjE1OTk0NzYifQ
function parse_signed_request(signed_request, secret) {
encoded_data = signed_request.split('.',2);
// decode the data
sig = encoded_data[0];
json = base64url.decode(encoded_data[1]);
data = JSON.parse(json); // ERROR Occurs Here!
@cyakimov
cyakimov / nodejs.sh
Created August 13, 2011 20:06 — forked from crcastle/nodejs.sh
Node.js startup script for AWS EC2 Linux box
#!/bin/bash
# nodejs - Startup script for node.js server
# chkconfig: 35 85 15
# description: node is an event-based web server.
# processname: node
# server: /path/to/your/node/file.js
# pidfile: /var/run/nodejs.pid
#
@cyakimov
cyakimov / gist:1147517
Created August 15, 2011 19:24
HTML5 in IE8 and below
<meta http-equiv="X-UA-Compatible" content="IE=Edge,chrome=1" />
<!--[if lt IE 9]>
<script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
@cyakimov
cyakimov / gist:1171968
Created August 25, 2011 21:09
Install NodeJS in CentOS / Fedora
yum groupinstall "Development Tools"
#get the lastest in nodejs.org
wget http://nodejs.org/dist/node-v0.4.11.tar.gz
tar xvzf node-v0.4.11.tar.gz
cd node-v0.4.11
./configure && make && make install
@cyakimov
cyakimov / gist:2117219
Created March 19, 2012 15:59
Animate numbers jQuery
//http://stackoverflow.com/questions/149055/how-can-i-format-numbers-as-money-in-javascript
Number.prototype.formatMoney = function(c, d, t){
var n = this, c = isNaN(c = Math.abs(c)) ? 2 : c, d = d == undefined ? "," : d, t = t == undefined ? "." : t, s = n < 0 ? "-" : "", i = parseInt(n = Math.abs(+n || 0).toFixed(c)) + "", j = (j = i.length) > 3 ? j % 3 : 0;
return s + (j ? i.substr(0, j) + t : "") + i.substr(j).replace(/(\d{3})(?=\d)/g, "$1" + t) + (c ? d + Math.abs(n - i).toFixed(c).slice(2) : "");
};
function animateNumberChange(el,number,callback, interval, relax_interval)
{
var currentVal = el.data("value");
var endVal = number;