Skip to content

Instantly share code, notes, and snippets.

View itissid's full-sized avatar

Sid itissid

  • New York
View GitHub Profile
@itissid
itissid / Trie.py
Created July 26, 2018 17:12
A simple Trie implementation
class Trie:
def __init__(self):
"""
Initialize your data structure here.
"""
self.root_dict = {}
def insert(self, word):
"""
@itissid
itissid / fun_orm.py
Created June 21, 2018 11:16 — forked from dmitric/fun_orm.py
A simple read-only ORM like functionality using python's __getattr__. Example uses tornado's torndb Connection and query
class Backend(object):
"""Allows access to backend and removes logic from handlers"""
def __init__(self):
"""Inititalize with the variables you need"""
self.__users_data = None
self.db = Connection(
options.db_host,
options.db,
user=options.db_user,
on run argv
set targetTabName to quoted form of (item 1 of argv)
set targetFullPath to (item 2 of argv)
tell application "Safari"
--Variables
set targetWindow to 0
set targetTab to 0
set found to false
--Repeat for Every Window
@itissid
itissid / tabrefresh_chrome.scpt
Created March 15, 2018 17:01
Open a file in chrome
on run argv
set targetTabName to quoted form of (item 1 of argv)
set targetFullPath to (item 2 of argv)
tell application "Google Chrome"
--Variables
set targetWindow to 0
set found to false
set targetTab to 0
--Repeat for Every Window
repeat with theWindow in every window
dependencies {
compile project(':foo'), project(':bar')
}
sgupta-mbp:~ sgupta$ cpan -l |grep LocalEnv
Can't stat /Network/Library/Perl/5.18/darwin-thread-multi-2level: No such file or directory
at /System/Library/Perl/5.18/App/Cpan.pm line 1216.
Can't stat /Network/Library/Perl/5.18: No such file or directory
at /System/Library/Perl/5.18/App/Cpan.pm line 1216.
App::PerlLocalEnv undef
Can't cd to (/Users/sgupta/.cpan/build/Module-Install-1.16-tf5h8B/) lib: Permission denied
at /System/Library/Perl/5.18/App/Cpan.pm line 1216.
Can't cd to (/Users/sgupta/.cpan/build/Module-Install-1.16-tf5h8B/) t: Permission denied
at /System/Library/Perl/5.18/App/Cpan.pm line 1216.
@itissid
itissid / gist:07bff5b677db1a95b6c3
Last active August 29, 2015 14:13
DP Text justification.
too_large = 1e12
def violations(words, page_width):
"""
The greater this is the worst the worst is the violation.
TODO(Sid): abs??
"""
cost = page_width - (sum(len(i) for i in words) + len(words) - 1)
if cost < 0:
return too_large
else:
{0.0007331374358727771,
0.0019193787255176176,
0.002652516161447238,
0.003838757451035235,
0.0050249987406445484,
0.005758136176552853,
0.006944377466169271,
0.00767751490207047,
0.008863756191658467,
0.010049997481289097,
# This is a proposed implementation of single source shortest path using DFS
class FailBowlDFS(object):
no_path_to_dest = 1e10 # more than any node
def __init__(self, tree, cost):
self.cost = cost
self.tree = tree
self.min_dist = {}
self.visited = set()
class Solution:
# @param root, a tree node
# @return a list of lists of integers
def levelOrder(self, root):
self.level_order_list = []
self.dfs_traverse(root, l = 0)
return self.level_order_list