Skip to content

Instantly share code, notes, and snippets.

View count_filled.py
import unittest
from selenium import webdriver
class CountFilled(unittest.TestCase):
def setUp(self):
self.driver = webdriver.PhantomJS()
def test_count_filled(self):
View next_bigger.py
import unittest
def next_bigger(l):
"""
This function returns a modified list
by appending a new element that is
bigger than the max element of the list
l = [], returns l[0]
View find_mode.py
import unittest
def find_mode(l):
if len(l) == 0:
return "ZeroLength"
l.sort()
sums = {}
View even_elements.py
import unittest
def even_elements(l):
"""
Given a list, this function returns a new list
with the with items found in the even indexes only
"""
if len(l) == 0:
return l
View love_rectangles.py
import unittest
def find_overlap(r1, r2, axis, result):
if axis is 'x':
start = 'x'
distance = 'width'
elif axis is 'y':
start = 'y'
distance = 'height'
p1 = r1[start]
@dudepare
dudepare / hired.py
Created Apr 20, 2016
This solution is from a recent ad by @Hired_HQ
View hired.py
def main(msg):
convert = map(chr, msg)
print("".join(list(convert)))
if __name__ == '__main__':
msg = [76, 101, 116, 116, 104, 101, 98, 101, 115, 116, 115, 116, 97, 114, 116,117, 112, 115, 97, 112, 112, 108, 121, 116, 111, 121, 111, 117, 0]
main(msg)
@dudepare
dudepare / compressed_string.py
Created Aug 10, 2016
String Compression: Implement a method to perform basic string compression using the counts of repeated characters. For example, the string aabcccccaaa would become a2blc5a3. If the "compressed" string would not become smaller than the original string, your method should return the original string. You can assume the string has only uppercase an…
View compressed_string.py
"""
String Compression: Implement a method to perform basic string
compression using the counts of repeated characters. For example,
the string aabcccccaaa would become a2blc5a3. If the "compressed"
string would not become smaller than the original string, your
method should return the original string. You can assume the
string has only uppercase and lowercase letters (a -z).
"""
def compress(inputstr):
if len(inputstr) == 0:
@dudepare
dudepare / sample_crypto_aes.js
Created Aug 10, 2016
This is a sample of AES encryption + decryption using CryptoJS. This is a bit different from the examples out there because this one uses a COMPANY header + payload. There's a little bit more processing going on. I also used a CDN for CryptoJS. I hope someone finds this useful.
View sample_crypto_aes.js
<script src="https://cdnjs.cloudflare.com/ajax/libs/crypto-js/3.1.2/components/core-min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/crypto-js/3.1.2/components/sha256.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/crypto-js/3.1.2/components/enc-base64.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/crypto-js/3.1.2/rollups/aes.js"></script>
<script>
function toWordArray(str){
return CryptoJS.enc.Utf8.parse(str);
}
function toString(words){
@dudepare
dudepare / matrix_rotate.py
Created Aug 17, 2016
Rotates an N x N matrix M 90 degrees clockwise.
View matrix_rotate.py
class Matrix:
@staticmethod
def rotate(m, n):
"""Rotates a matrix m of n x n size"""
# reverse each row of the matrix
for i in range(n):
m[i] = m[i][::-1]
@dudepare
dudepare / zero_matrix.py
Created Aug 19, 2016
Zero Matrix: Write an algorithm such that if an element in an MxN matrix is 0, its entire row and column are set to 0.
View zero_matrix.py
class Matrix:
@staticmethod
def zero(M, m, n):
"""Zeroes out the whole row and column if one elements is found to be zero.
Args:
M (array) of m rows and n columns
m (int) of rows
n (int) of columns