Skip to content

Instantly share code, notes, and snippets.

@kixorz
kixorz / module1.js
Last active December 25, 2015 03:49
Example of design pattern for Node.js modules.
var module1 = function(param1, param2) {
var m_param1 = param1;
var m_param2 = param2;
var private_method = function(param3) {
return param3 + m_param1 + m_param2;
};
return {
public_method1: function(param1) {
@kixorz
kixorz / chef.txt
Created September 17, 2013 20:38
Chef Notes
# bootstrapping new node:
knife bootstrap <hostname> -x <username> -P <password> --sudo
@kixorz
kixorz / payment.html
Created August 26, 2013 21:30
It's terrible to use meta tag order sematics to define multiple items: https://developers.facebook.com/docs/howtos/payments/definingproducts/#ogproduct_item
<meta property="product:price:amount" content="0.99"/>
<meta property="product:price:currency" content="USD"/>
<meta property="product:price:amount" content="0.79"/>
<meta property="product:price:currency" content="EUR"/>
@kixorz
kixorz / gist:6084158
Last active December 20, 2015 06:09
Useful gdb commands
Unlimited gdb print command:
set print elements 0
Print void* string content:
p (char *)variable+16
@kixorz
kixorz / age.rb
Created June 20, 2013 04:19
Getting age in years from Time or Date object.
def age(time)
if time.kind_of?(Date)
timestamp = time.to_time.to_i
elsif time.kind_of?(Time)
timestamp = time.to_i
else
return 0
end
(Time.now.to_i - timestamp) / 31536000
@kixorz
kixorz / aws_cycle_elastic_ip.rb
Last active December 18, 2015 11:49
Script for cycling of Elastic IP attached to Amazon EC2 instance. Script also updates selected Route53 A record.
#!/usr/bin/env ruby
require 'syslog'
require 'net/http'
require 'aws-sdk'
Syslog.open
AWS.config({
:access_key_id => '<iam user key>',
:secret_access_key => '<iam user secret>'
@kixorz
kixorz / nginx.sh
Created April 14, 2013 05:10
Installation of rvm, rails, passenger, nginx
#rvm
\curl -#L https://get.rvm.io | sudo bash -s stable --autolibs=3 --ruby
#passenger
gem install passenger --pre
#nginx
#http://nginx.org/en/download.html
#set paths
@kixorz
kixorz / create.sql
Last active December 15, 2015 19:29
Create user and db on PostgreSQL
CREATE USER <user> WITH PASSWORD '<password>';
CREATE DATABASE <db>;
CREATE SCHEMA <schema>;
GRANT ALL PRIVILEGES ON DATABASE <db> TO <user>;
GRANT ALL PRIVILEGES ON SCHEMA <schema> TO <user>;
GRANT ALL PRIVILEGES ON ALL TABLES IN SCHEMA <schema> TO <user>;
#clone db command
createdb -O <owner> -T <db> <new db>
@kixorz
kixorz / crontab
Last active June 18, 2017 11:14
Running Rake tasks from Cron with RVM. Place the crontab.sh file in the root of your Rails project and make it executable. Edit crontab accordingly.
#run a command every day at midnight under user ubuntu
0 0 * * * ubuntu /<path to your rails project>/crontab.sh bundle exec rake <parameters> > /dev/null 2> /dev/null
@kixorz
kixorz / facebook_js_close_ui.js
Last active December 15, 2015 15:29
Closing Facebook JS SDK dialog window from your code.
//I found out that I’d need to close Facebook dialog that I invoke by calling:
FB.ui(<parameters>, <callback>);
//Facebook, doesn’t provide any documentation do these dialogs, with one exception - how to open them, so I had to manually trace how they close the dialog window. I found out that it’s a good practice to open all their dialogs like this
//open the dialog and save off the reference
var dialog = FB.ui(<parameters>, <callback>);
...
//force close the dialog via it's id accessible through the saved reference