Skip to content

Instantly share code, notes, and snippets.

View marcinwyszynski's full-sized avatar

Marcin Wyszynski marcinwyszynski

View GitHub Profile
@marcinwyszynski
marcinwyszynski / anagrams.py
Created January 12, 2012 15:12
Anagram finder for Unix-like systems
#!/usr/bin/env python
import sys
try:
word = sys.argv[1]
except IndexError:
print 'usage: anagrams.py <word>'
exit(1)
@marcinwyszynski
marcinwyszynski / priority_queue.rb
Created January 12, 2012 12:50
A simple PriorityQueue in Ruby
class PriorityQueue
def initialize() @store = {} end
# Takes element and it's priority.
# Returns an array of elements with the same priority.
def enq(el, p)
@store[p] ? @store[p].push(el) : @store[p] = [el]
return @store[p]
end
@marcinwyszynski
marcinwyszynski / priority_queue.py
Created January 12, 2012 12:47
A simple PriorityQueue in Python
class PriorityQueue(object):
def __init__(self):
self.store = {}
def enq(self, element, weight):
if weight in self.store:
self.store[weight].append(element)
else:
self.store[weight] = [element]
@marcinwyszynski
marcinwyszynski / power_of_two.rb
Created January 12, 2012 01:09
Checking if an integer is a power of 2
Integer::class_eval do
def power_of_2?() (self & (self - 1)) == 0 end
end