Skip to content

Instantly share code, notes, and snippets.

View DronRathore's full-sized avatar

Dron Rathore DronRathore

View GitHub Profile
@DronRathore
DronRathore / c-ares-test.log
Last active March 11, 2020 09:12
Test logs at commit 671e0b23bfa9245be8ea8f94acd513b3e1ebbcfb
[==========] Running 451 tests from 22 test cases.
[----------] Global test environment set-up.
[----------] 5 tests from LibraryInit
[ RUN ] LibraryInit.Basic
[ OK ] LibraryInit.Basic (0 ms)
[ RUN ] LibraryInit.UnexpectedCleanup
[ OK ] LibraryInit.UnexpectedCleanup (0 ms)
[ RUN ] LibraryInit.Nested
[ OK ] LibraryInit.Nested (0 ms)
[ RUN ] LibraryInit.BasicChannelInit
@DronRathore
DronRathore / user_agent.rl.go
Created June 21, 2017 10:26
User Agent name and Version extraction using ragel machine
package helper
// Call this function with User Agent header
func UaVersion(agent string) (string, string) {
var bytes []byte = make([]byte, len(agent))
copy(bytes[:], agent)
return _uaVersion(bytes)
}
func extractVersion(fc byte, version string, lastversion *string) string {
@DronRathore
DronRathore / binary_tree_mod.cc
Created May 29, 2017 09:09
Binary Search Tree
// Author: Dron Rathore <dron(.)rathore[(@)]G-Mail>
// A modified C++ implementation for Binary Search Tree
// Every node keeps a parent node ref to help the deletion
// in Θ(log(n)) complexity.
// This is no rocket science, same can be acheived with
// double pointers where you perform a look ahead search in
// the tree in case of deletion so you have parent of the
// Right Subtree's largest node which comes handy.
@DronRathore
DronRathore / express_router_regex.go
Last active September 17, 2016 19:56
Convert Go http routes to express-js fashion
package main
import "os"
import "text/tabwriter"
import "regexp"
import "fmt"
func main(){
// silent the groups to eliminate redundant data in match
var r = compileRegex("/:name/:service/:id(?:[0-9]{0,3})")
var regex = r.FindStringSubmatch("/api/buy/123")
@DronRathore
DronRathore / clean.sh
Last active November 3, 2015 17:20
Removes .DS_STORE and underscore files from any folder
#!/bin/bash
# Browsing directories on mac creates .DS_STORE and further
# it create similar files for any file you open
# it is annoying to see such files in a github repo folder and often
# we end up pushing them in our codebase
# so here is a one liner solution to remove .DS_STORE and other ._files from git
# run junk for non git repo, or cg for git repo, you can add this in your .bash_profile too.
# Add the below lines in your .bash_profile, run source ~/.bash_profile and done
@DronRathore
DronRathore / object_id.js
Created August 21, 2015 14:52
Generate Unique Object IDs
/*
Generate unique IDs for Objects
*/
(
function(ref){
ref.__counting_tick_var = 0;
Object.prototype.id = function(){
return (
this.__counting_tick_var ?
this.__counting_tick_var :
@DronRathore
DronRathore / array.js
Created August 20, 2015 13:01
Array Init vs Array.push
/*
Adding values in array at init using variables is faster
then processing individual entity
*/
function A(options){
var a = [ “something” + options.A + “more”, “second elem” + options.B + “Yo!”]
return A;
}
function B(options){
var a = [];
@DronRathore
DronRathore / animation_frame_sample.js
Created February 8, 2015 18:18
requestAnimationFrame
/*
Sample from MDN
*/
var start = null;
var element = document.getElementById("SomeElementYouWantToAnimate");
function step(timestamp) {
if (!start) start = timestamp;
var progress = timestamp - start;
element.style.left = Math.min(progress/10, 200) + "px";
@DronRathore
DronRathore / law_proof.js
Last active August 29, 2015 14:15
setTimeout = setInterval
/*
Law: clearInterval = clearTimeout
*/
var a = setTimeout(function(){console.log(1)}, 100);
clearInterval(a);
var b = setInterval(function(){console.log(1)}, 100);
clearTimeout(b);
/*
Nothing will be logged on console!
We cleared the timers!
@DronRathore
DronRathore / simple_timeout.js
Created February 8, 2015 16:47
Simple Timeout
var time = Date.now();
setTimeout(function(){console.log("I was fired after: ", Date.now()-time, "ms")}, 1);
/*
Output = I was fired after: 1 ms
*/