Skip to content

Instantly share code, notes, and snippets.

@Alfreddd
Alfreddd / localTimezone.js
Created October 17, 2013 10:33
detect client timezone
//********* Timezone calculation
var localTimezone = function(){
var timezone = ""
var d = new Date;
var offset = d.getTimezoneOffset()
timezone = (offset > 0) ? "-" : "+"
offset = offset / 60 * (-100)
var paddedOffset = pad(""+offset,4,'0');
return timezone + paddedOffset
}
@Alfreddd
Alfreddd / mysql2_ruby193_osx32bit
Created October 5, 2012 22:48
mysql2 ruby193 osx 32bit
1. first check the kernel architecture using
uname-m
2. download and install the proper mysql server
3. if u got this error when running server
dyld: lazy symbol binding failed: Symbol not found:
_mysql_get_client_info
then u have to update mysql2 gem using
@Alfreddd
Alfreddd / rbenv32.txt
Created October 5, 2012 22:09
rbenv install 32bit ruby version
CONFIGURE_OPTS="--with-arch=i386" CFLAGS="-arch i386" LDFLAGS="-arch i386" rbenv install 1.9.3-p194
@Alfreddd
Alfreddd / pow_https.txt
Created October 5, 2012 21:50
Pow to server https
http://shiny-bits-of-code.tumblr.com/post/4749553253/ssl-proxy-with-nginx
http://www.cyberciti.biz/faq/howto-linux-unix-setup-nginx-ssl-proxy/
@Alfreddd
Alfreddd / open connections (sockets) for process
Created June 20, 2012 17:31
list/count open connections (sockets) for All/certain process
# list open sockets for PID
sudo lsof -p 13264 | egrep 'TCP|UDP'
# count of sockets
sudo lsof -p 13264 | egrep "TCP|UDP" | wc -l
# list the open sockets for all passengers
passenger-status | grep PID | awk '{ print $3}' | xargs -i sudo lsof -p {} | egrep 'TCP|UDP'
@Alfreddd
Alfreddd / macporst.txt
Created June 5, 2012 12:45
using macports to install libxml
sudo port install libiconv +universal
sudo port install libxml2 +universal
sudo port install libxslt+universal
@Alfreddd
Alfreddd / find_dups.rb
Created November 23, 2011 10:16
Find duplicates in Array
# http://snippets.dzone.com/posts/show/4148
class Array
def find_dups
inject(Hash.new(0)) { |h,e| h[e] += 1; h }.select { |k,v| v > 1 }.collect { |x| x.first }
end
end
@Alfreddd
Alfreddd / mysql2_gem_install
Created October 11, 2011 15:45
Installing mysql2 gem on Windows -- Ruby 1.9.2 with devkit
gem install mysql2 -v 0.2.11 --platform=ruby -- '--with-mysql-dir="C:\Program Files\MySQL\MySQL Server 5.1" --with-mysql-lib="C:\Program Files\MySQL\MySQL Server 5.1\lib\opt"'
@Alfreddd
Alfreddd / convert_seconds_to_time.rb
Created October 2, 2011 10:03
convert seconds to the form "10m 20s"
def convert_seconds_to_time(seconds)
total_minutes = seconds / 1.minutes
seconds_in_last_minute = seconds - total_minutes.minutes.seconds
"#{total_minutes}m #{seconds_in_last_minute}s"
end