Skip to content

Instantly share code, notes, and snippets.

View RohitRox's full-sized avatar
🎯
Focusing

Rohit Joshi RohitRox

🎯
Focusing
View GitHub Profile
@RohitRox
RohitRox / em.rb
Last active December 16, 2015 03:19
one-to-one websockets
EventMachine.run do
EM::WebSocket.start(:host => "0.0.0.0", :port => 8080, :debug => false) do |ws|
ws.onopen do
ws.onmessage { |data|
# ...
# ws.send
}
@RohitRox
RohitRox / websocket_helper.js
Last active December 16, 2015 03:29
websocket helper, managing websocket events and callbacks
var ws = new WebSocket("ws://localhost:8080/");
ws.onopen = function() {
this.send(JSON.stringify({event: "init",data: { c_wid: "51396e790662720c10000002" } }));
};
ws.onmessage = function(evt){
var json = JSON.parse(evt.data);
console.log(json);
this.dispatch(json.event, json.data);
};
@RohitRox
RohitRox / to_hh_mm_ss.js
Created April 15, 2013 07:07
js string helper for string to hh:mm:ss
String.prototype.toHHMMSS = function () {
sec_numb = parseInt(this);
var hours = Math.floor(sec_numb / 3600);
var minutes = Math.floor((sec_numb - (hours * 3600)) / 60);
var seconds = sec_numb - (hours * 3600) - (minutes * 60);
if (hours < 10) {hours = "0"+hours;}
if (minutes < 10) {minutes = "0"+minutes;}
if (seconds < 10) {seconds = "0"+seconds;}
var time = hours+':'+minutes+':'+seconds;
@RohitRox
RohitRox / map and maps.html
Created April 17, 2013 12:00
map and maps
<!DOCTYPE html>
<html>
<head>
<title>Google Developers</title>
<link rel="stylesheet" type="text/css" href="/_static/css/screen.css" />
<link rel="stylesheet" href="//www.google.com/cse/style/look/default.css" type="text/css" />
<link href='http://fonts.googleapis.com/css?family=Open+Sans:300,400' rel='stylesheet' type='text/css'>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js"></script>
<script id="jqueryui" src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.10/jquery-ui.min.js" defer async></script>
<!--[if lt IE 9]>
@RohitRox
RohitRox / gist:5423027
Created April 19, 2013 20:30
fb access tokens
Fortunately, if you are trying to get the stream of a Facebook Page, there IS a better way. And one to get access tokens that never expire for pages.
Note: You need to A) be logged into FB, and B) be an admin for the page for which you are trying to get the stream.
1. Create an app on FB for your website. After creating it, make sure toe add your domain to App Domains and check Website with Facebook Login underneath “Select how your app integrates w FB” and provide your Site URL (which will be the oauth redirect_uri).
2. Visit the following to generate a new SHORT-LIVED (1 hour) access token:
https://www.facebook.com?
client_id=[APPID]&

Sublime Text 2 – Useful Shortcuts (PC)

Loosely ordered with the commands I use most towards the top. Sublime also offer full documentation.

Editing

Ctrl+C copy current line (if no selection)
Ctrl+X cut current line (if no selection)
Ctrl+⇧+K delete line
Ctrl+↩ insert line after

Todo.rb

Todo.rb is a simple command-line tool for managing todos. It's minimal, straightforward, and you can use it with your favorite text editor.

Getting Started

Todo.rb doesn't require any third-party gems so you can copy the file anywhere and use it as long as it's executable:

@RohitRox
RohitRox / up_and_running_ruby_on_rails.md
Last active December 18, 2015 05:39
setting ruby on rails development environment in linux

Step 1: Setting up RVM

    $ sudo apt-get update
    $ sudo apt-get install curl
    $ curl -L https://get.rvm.io | bash -s stable
    $ source ~/.rvm/scripts/rvm 

In order to work, RVM has some of its own dependancies that need to be installed. You can see what these are:

@RohitRox
RohitRox / ruby_method_adding
Created June 19, 2013 05:10
useful methods additions for ruby core classes
class Numeric
def roundup(nearest=10)
self % nearest == 0 ? self : self + nearest - (self % nearest)
end
def rounddown(nearest=10)
self % nearest == 0 ? self : self - (self % nearest)
end
end
puts 2.roundup #=> 10
puts 23.roundup #=> 30
@RohitRox
RohitRox / app_helpers.js
Last active December 19, 2015 16:28
Collection of Js helpers
Array.prototype.clean = function(deleteValue) {
for (var i = 0; i < this.length; i++) {
if (this[i] == deleteValue) {
this.splice(i, 1);
i--;
}
}
return this;
};