Skip to content

Instantly share code, notes, and snippets.

@paraggupta1993
paraggupta1993 / TerminateEvent
Last active August 29, 2015 14:04
teminateEvent : Stops bubbling-up and propogation of events in EventHandlers.
terminateEvent = function(event){
event.stopPropagation(); // Stops Bubbling up to Ancestor elements
event.preventDefault(); // Stops the default action Eg : Redirecting to a "href" for anchor element
return false;
}
$("#anchor-element").click( function(event){
//Do something
return terminateEvent();
});
@paraggupta1993
paraggupta1993 / add_parameter_to_url.coffee
Last active August 29, 2015 14:06
Adding a parameter to URL string using Coffeescript.
@addAttributeToUrl: (url, key, val) ->
return url if _.some arguments, (arg) ->
arg == null or arg == ''
#regex = (all non-# or non-?)(0-1: # or ?)(all non-blanks)
regex = /([^\?#]*)([?#]?)([^\s]*)/
match = regex.exec(url.trim())
baseUrl = match[1]
separator = match[2]
queryString = match[3]
@paraggupta1993
paraggupta1993 / tm.js
Created June 2, 2015 11:24
[Javascript] Turing Machine
function tm(tape, transform, startState, endStates, i){
currState = startState;
while(currState is not in endStates){
sym = (tape[i])? tape[i]: 'Blank';
state = transform[currState][sym];
if(!state) return 'Not Halting';
tape[i] = state.w; // write sym
i += state.m; // move tape
currState = state.n; // move to next state
}
#!/bin/bash
umount /dev/sdb1
sudo mkdosfs -n 'USB-Drive-Name' -I /dev/sdb -F 32
sudo dd if=filename.iso of=/dev/sdb bs=4k
sync
sudo eject /dev/sdc
# isohybrid filename.iso # only if there is "Missing Operating System" error in booting