Skip to content

Instantly share code, notes, and snippets.

View vireshas's full-sized avatar
:octocat:

Viresh Sanagoudar vireshas

:octocat:
View GitHub Profile
@vireshas
vireshas / consist_hash.java
Last active October 2, 2018 15:13 — forked from bcambel/consist_hash.java
Consistent Hash Java implementation
import java.util.Collection;
import java.util.SortedMap;
import java.util.TreeMap;
public class ConsistentHash<T> {
private final HashFunction hashFunction;
private final int numberOfReplicas;
private final SortedMap<Integer, T> circle = new TreeMap<Integer, T>();
@vireshas
vireshas / runWatch.sh
Created August 7, 2018 07:39 — forked from osrec/runWatch.sh
Watch a particular directory for changes and kill and restart a process on change
# In the example below, the command we want to run is `php -f "$DIR/../run.php"` - change this on lines 30 and 46
# $DIR is just the directory containing this script file (computed automatically, but you can hardcode it if you want).
# Use $DIR to specify paths relative to the script's path.
# The PROCESS_NAME variable is the name of the process to kill and restart
# You must ensure your process has the same name each time it runs (we use a file at $DIR/../servername to store the name)
# Alternatively, you can hard code the PROCESS_NAME on line 15 if you like
#!/bin/bash
# References:
# http://blog.mixu.net/2011/08/13/nginx-websockets-ssl-and-socket-io-deployment/
# http://blog.exceliance.fr/2012/09/10/how-to-get-ssl-with-haproxy-getting-rid-of-stunnel-stud-nginx-or-pound/
#
global
nbproc 2
maxconn 16384
defaults
@vireshas
vireshas / bad_code.clj
Created July 5, 2018 08:51
bad_code.clj
(def path ["abc" "def" "xyz" "ref" "fed"])
(defn a []
(->> path
(interpose "/")
(into ["/"])
(apply str)))
(defn b []
(str "/" (clojure.string/join #"/" path)))
module B
def print
puts C::A
end
end
class C
A = 10
include B
end
@vireshas
vireshas / here_hold_my_coffee.rb
Last active May 17, 2018 07:20
Dev: how do i define_methods on a class?
class C
class << self
define_method(:a) do |msg|
"hello #{msg}"
end
end
end
puts C.a("world")
@vireshas
vireshas / url_params_to_py_dict.py
Last active May 1, 2018 10:32
convert url params to python dict
url_params = "a=b&c=d&e=f&g=h"
dict([i.split('=') for i in url_params.split("&")])
@vireshas
vireshas / main.go
Created January 8, 2018 06:40 — forked from creack/main.go
A simple golang web server with basic logging, tracing, health check, graceful shutdown and zero dependencies
package main
import (
"context"
"fmt"
"log"
"net/http"
"os"
"os/signal"
"strconv"
#colleague asks
class A
attr_accessor :b,:d
def a
self.b = 10
@d = 20
end
<html>
<head>
<script type="text/javascript" src="http://cdn.clappr.io/latest/clappr.min.js"></script>
<script type="text/javascript" src="http://cdn.jsdelivr.net/clappr.rtmp/0.0.2/rtmp.min.js"></script>
</head>
<body>
<div id="player"></div>
<script>
window.onload = function() {
var player = new Clappr.Player({