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 / url_params.js
Created June 26, 2012 18:24
Read url params with javascript
// one way
function getUrlVars() {
var vars = {};
var parts = window.location.href.replace(/[?&]+([^=&]+)=([^&]*)/gi, function(m,key,value) {
vars[key] = value;
});
return vars;
}
@RohitRox
RohitRox / jquery.tabbie.js
Created July 18, 2012 11:24
Very small re-usable tabbifying jquery plugin
// Very small re-usable tabbifying jquery plugin , @roxxypoxxy
// Usage
/**
The list
<ul class="my-tabs">
<li rel="div1">Div One</li>
<li rel="div2">Div Two</li>
</ul>
@RohitRox
RohitRox / ruby_csv _to_hash
Created January 17, 2013 08:01
csv to hash
require 'csv'
csv = CSV::parse(File.open(path_to_file, 'r') {|f| f.read })
fields = csv.shift
csv.collect { |record| Hash[*(0..(fields.length - 1)).collect {|index| [fields[index],record[index].to_s] }.flatten ] }
@RohitRox
RohitRox / ruby_notepad_bookmarklet
Created January 30, 2013 03:39
Ruby Notepad Bookmarklet
data:text/html, <style type%3D"text%2Fcss">%23e{position%3Aabsolute%3Btop%3A0%3Bright%3A0%3Bbottom%3A0%3Bleft%3A0%3B}<%2Fstyle><div id%3D"e"><%2Fdiv><script src%3D"http%3A%2F%2Fd1n0x3qji82z53.cloudfront.net%2Fsrc-min-noconflict%2Face.js" type%3D"text%2Fjavascript" charset%3D"utf-8"><%2Fscript><script>var e%3Dace.edit("e")%3Be.setTheme("ace%2Ftheme%2Fmonokai")%3Be.getSession().setMode("ace%2Fmode%2Fruby")%3B<%2Fscript>
require 'rubygems'
require 'capybara'
require 'capybara/dsl'
Capybara.run_server = false
Capybara.current_driver = :selenium
Capybara.app_host = 'http://...'
module MyCapybara
class FireBro
include Capybara::DSL
@RohitRox
RohitRox / app.rb
Last active December 15, 2015 13:08
require 'rubygems'
require 'capybara'
require 'capybara/dsl'
require 'pry'
require 'yaml'
require 'json'
require "net/http"
require "uri"
Capybara.run_server = false
@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]>