Skip to content

Instantly share code, notes, and snippets.

View itissid's full-sized avatar

Sid itissid

  • New York
  • 10:19 (UTC -12:00)
View GitHub Profile
CREATE TABLE tweets (
... user text,
... time timestamp,
... tweet text,
... lat float,
... long float,
... PRIMARY KEY (user, time)
... );
@itissid
itissid / TrieFromScratch.py
Last active August 3, 2018 16:02
A trie from scratch.
import string
class TrieNode(object):
"""
Context: Implementation of the trie using a dictionary is trivial:
https://gist.github.com/itissid/6a5bec95424b5630908e877c02d957d5
But if one was to implement the Trie node as a DS then one needs to think about implementation a bit more.
So what I did was keep the API code for search, insert, search_prefix the same as the gist; i.e.
to pretend we are still using a dictionary, but I implemented some magic methods for the trie in the TrieNode (
@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,