Skip to content

Instantly share code, notes, and snippets.

@nsfyn55
nsfyn55 / tree_search.py
Created June 7, 2015 13:29
Depth and Breadth First Tree Traversals
from collections import deque
class Node(object):
left = None
right = None
value = None
def __init__(self, left, right, value):
self.left = left
self.right = right
@nsfyn55
nsfyn55 / hour-problems.py
Last active August 29, 2015 14:20
Search example from "Problems every software developer should be able to solve in under an hour"
"""
From programming problems every software developer should be able to solve in
under an hour.
Given an array of integers find the largest integer they can be combined to
form.
for instance [50, 2, 1, 9, 62] would yield the answer 9625021
"""
@nsfyn55
nsfyn55 / gist:c1ca64e580f60a3f78a3
Last active August 29, 2015 14:20
Convert Timezone Aware Date to Timezone unaware UTC Equivalent
from dateutil.parser import parse
from pytz import utc
datestr = 'Fri, 24 Apr 2015 14:49:32 -0400'
dt = parse(datestr)
utc_dt = dt.astimezone(utc)
final = utc_dt.replace(tzinfo=None)
@nsfyn55
nsfyn55 / predictions.py
Last active August 29, 2015 14:02
Stack Predictions Sample
from collections import namedtuple
from wtforms import Form, IntegerField, FieldList, FormField, TextField
from werkzeug.datastructures import MultiDict
Prediction = namedtuple('Prediction', ['id'])
predictions = [Prediction(id=1), Prediction(id=2)]
class PredictionForm(Form):
id = IntegerField()
@nsfyn55
nsfyn55 / curved.py
Created May 30, 2014 00:40
One liner find curved numbers
print [for num in ['33','14','96'] if set(num).intersection(set(['0','2','3','5','6','8','9']))]
@nsfyn55
nsfyn55 / curved.py
Last active August 29, 2015 14:01
Find curved numbers interview question
s = set(['0','2','3','5','6','8','9'])
l = ['33', '14', '19']
# as loop
for num in l:
charset = set(num)
if charset.intersection(s):
print num
# as comprehension
#
# Wide-open CORS config for nginx
#
location / {
if ($request_method = 'OPTIONS') {
add_header 'Access-Control-Allow-Origin' '*';
#
<!-- Sample Site http://nsfyn55.fortune.site.s3-website-us-east-1.amazonaws.com/ -->
<html>
<head>
<meta http-equiv="Content-Type" content="text/html"; charset="UTF-8"/>
<title>Page Title</title>
<link rel="stylesheet" type="text/css" href="test.css">
<link rel="stylesheet" type="text/css" href="dhtmlxslider.css">
<script type="text/javascript" src="d3.js"></script>
<script type="text/javascript" src="dhtmlxcommon.js"></script>
<script type="text/javascript" src="dhtmlxslider.js"></script>
@nsfyn55
nsfyn55 / sieve.py
Created October 17, 2013 20:10
Sieve of Erasthostenes
def create_list(n):
l = []
for x in range(2,n+1):
l.append(x)
return l
def get_remove_factors(start, n, inc):
s = set()
for i in range(start, n+1, inc):
if i > start:
@nsfyn55
nsfyn55 / conway.py
Last active December 24, 2015 09:39
Conway's game of life
def tick(world):
output_world = world.copy()
if len(world) <= 2:
return set()
for cell in world:
if len(get_live_neighbors(cell, world)) < 2:
output_world.remove(cell)