Skip to content

Instantly share code, notes, and snippets.

Avatar
💚
Lobe

Adam Menges adammenges

💚
Lobe
View GitHub Profile
View gist:4643277
def fizzbuzz(n):
for i in xrange(1, n+1): print [i, 'Fizz', 'Buzz', 'FizzBuzz'][(i%3 == 0) + 2 * (i % 5 == 0)]
View question1-1.java
public boolean inUnique(string str) {
boolean[] chars = new boolean[256]; // Size only works with ASCII, increase otherwise.
for(int i=0; i<str.size(); i++){
if(chars[str.charAt(i)]) return false;
chars[str.charAt(i)] = true;
}
return true;
}
View question1-2.java
public boolean isUnique(string str) {
for(int i=0; i<str.size(); i++){
for(int j=0; j<str.size(); j++) {
if(i==j) continue;
else if(str.charAt(j) == str.charAt(i)) return false;
}
}
return true;
}
View validParentheses.rb
def validParentheses? str
a = []
str.each_char do |x|
if x == '('
a.push x
elsif x == ')'
return false if a.pop == nil
end
end
a.empty?
View problemcode.c
unsigned int i;
for(i=100; i<=0; --i)
print(i)
View shuffleCards.java
public void shuffleCards (int[] cards){
int temp, index;
for (int i = 0; i < cards.length; i++){
index = (int) (Math.random() * (cards.length - i)) + i;
temp = cards[i];
cards[i] = cards[index];
cards[index] = temp;
}
}
@adammenges
adammenges / FizzBuzz.py
Last active Jan 1, 2016
One liner FizzBuzz
View FizzBuzz.py
def fizzbuzz(n):
print "\n".join([('Fizz'*(not i%3) + 'Buzz'*(not i%5)) if ((not i%3) or (not i%5)) else str(i) for i in xrange(1, n+1)])
View fib.py
def fib(n):
return reduce(lambda x, y: [x[1], x[0] + x[1]], xrange(n-2), [0, 1])[1]
View isUnique.py
from collections import defaultdict
def isUnique(string):
seen = defaultdict(lambda: False)
for x in string:
if not seen[x]: seen[x] = True
else: return False
return True
View netgear_telnet_enabler.rb
require 'msf/core'
require 'crypt/blowfish' # sorry, openssl is limited to 16-byte key size :(
# add gem 'crypt', '1.1.4' to Gemfile
module ::Crypt
class Blowfish
def setup_blowfish()
@sBoxes = Array.new(4) { |i| INITIALSBOXES[i].clone }
@pArray = INITIALPARRAY.clone
keypos = 0