Skip to content

Instantly share code, notes, and snippets.

Avatar

Shadab Ahmed shadabahmed

View GitHub Profile
@shadabahmed
shadabahmed / skip_list.rb
Created Jun 10, 2018
Skip List Ruby Implementation
View skip_list.rb
INFINITY = 1.0 / 0
NEG_INFINITY = -1.0 / 0
class Node
MAX_LEVEL = 7
# node has value and levels
attr_accessor :val, :levels
def initialize(val)
self.val = val
self.levels = []
View aggrobot.rb
=begin
{
"region1": {month1: {avg_target: xxx, avg_actual: xxx}
month2: .........
}
=end
@shadabahmed
shadabahmed / logstash-cert.sh
Last active Jul 31, 2017
Lumberjack - init.d and config files. Copy the init.d script to /etc/init.d/lumberjack and add execute permissions. Copy the config file lumberjack to /etc/default/lumberjack file.
View logstash-cert.sh
# Create Key
openssl genrsa -des3 -out logstash.key 1024
sudo openssl genrsa -des3 -out logstash.key 1024
# Create CSR
openssl req -new -key logstash.key -out logstash.csr
sudo openssl req -new -key logstash.key -out logstash.csr
# Remove password from key
sudo openssl rsa -in logstash.key.org -out logstash.key
# Create certificate
sudo openssl x509 -req -days 365 -in logstash.csr -signkey server.key -out logstash.crt
@shadabahmed
shadabahmed / logstash-suse
Last active Mar 16, 2017
Logstash init.d script and config file. Ubuntu script is borrowed from http://www.vmdoh.com/blog/centralizing-logs-lumberjack-logstash-and-elasticsearch SuSe script is for SLES. Just copy the script to /etc/init.d as logstash
View logstash-suse
#! /bin/sh
### BEGIN INIT INFO
# Provides: logstash
# Required-Start: $remote_fs $syslog
# Required-Stop: $remote_fs $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Start daemon at boot time
# Description: Enable service provided by daemon.
### END INIT INFO
View skyline_tree.rb
class SkylineTree
attr_reader :root
def initialize(node_class = Node, start = nil, value = nil)
@node_class = node_class
@root = start && tree_type.new(start, value)
end
def add(range, value = nil)
if root
@shadabahmed
shadabahmed / index.html
Created Apr 19, 2013
A CodePen by Shadab Ahmed. Soduko Solver - Simple sudoko solver where we have atleast one unambigous cell all the time when solving the puzzle
View index.html
<section>
<table class="grid">
<tbody>
<tr> <td> <td> <td> <td> <td> <td> <td> <td> <td>
<tr> <td> <td> <td> <td> <td> <td> <td> <td> <td>
<tr> <td> <td> <td> <td> <td> <td> <td> <td> <td>
<tr> <td> <td> <td> <td> <td> <td> <td> <td> <td>
<tr> <td> <td> <td> <td> <td> <td> <td> <td> <td>
<tr> <td> <td> <td> <td> <td> <td> <td> <td> <td>
<tr> <td> <td> <td> <td> <td> <td> <td> <td> <td>
@shadabahmed
shadabahmed / index.html
Created Apr 18, 2013
A CodePen by Shadab Ahmed.
View index.html
<section>
<table class="grid">
<colgroup><col><col><col>
<colgroup><col><col><col>
<colgroup><col><col><col>
<tbody>
<tr> <td> <td> <td> <td> <td> <td> <td> <td> <td>
<tr> <td> <td> <td> <td> <td> <td> <td> <td> <td>
<tr> <td> <td> <td> <td> <td> <td> <td> <td> <td>
<tr> <td> <td> <td> <td> <td> <td> <td> <td> <td>
@shadabahmed
shadabahmed / parens_permute.rb
Last active Dec 16, 2015
A tree for creating parenthesis permutation
View parens_permute.rb
require 'graphviz'
class LeveledBinaryTree
Node = Struct.new(:weight, :str, :left, :right)
attr_accessor :levels, :root
def initialize(clear_last_level = true)
@root = Node.new(1, '(')
@levels = {0 => [@root]}
@shadabahmed
shadabahmed / index.html
Created Mar 23, 2013
A CodePen by Shadab Ahmed.
View index.html
<div class="rumor">
<div class="dropdown">
<label>Algorithm:</label>
<select id="algo">
</select>
&nbsp;
<label>Number of People:</label>
<input id="count" type="text" value="60" name="count"/>
<label>Speed:</label>
<select name="speed" id="speed">
@shadabahmed
shadabahmed / range_count_tree.rb
Last active Dec 14, 2015
Range Count Tree For problems like given n ranges, find the interval when maximum ranges intersect
View range_count_tree.rb
# RangeCountTree
# A bst variant for fast retrieval of count of ranges which are intersecting given n ranges
#
# Creator : Shadab Ahmed
#
# Each node stores a range and the count of intervals which intersect with the range.
#
# We just follow these rules:
# 1. Any range which is greater than the current range is stored in the right subtree
# 2. Any range which is smaller than the current range is stored in the left subtree
You can’t perform that action at this time.