Skip to content

Instantly share code, notes, and snippets.

Daniel Chia danielcodes

Block or report user

Report or block danielcodes

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@danielcodes
danielcodes / solve.py
Created Apr 6, 2020
269. Alien dictionary
View solve.py
def solve(words):
def build_graph(words, indegree, adj):
# initialize map with all possible nodes
for x in range(len(words)):
for y in range(len(words[x])):
if y not in adj:
adj[words[x][y]] = set()
for i in range(1, len(words)):
@danielcodes
danielcodes / solve.py
Created Apr 6, 2020
271. Encode and decode strings
View solve.py
def encode(words):
ans = ''
# count-word is the encoding
for i in range(len(words)):
ans += str(len(words[i])) + '-' + words[i]
return ans
@danielcodes
danielcodes / solve.py
Created Apr 6, 2020
261. Graph vaild tree
View solve.py
from collections import defaultdict
def solve(n, edges):
def has_cycle(node, parent, adj, visited):
visited.add(node)
for n in adj[node]:
# node has been visited and not the parent
if n in visited and n != parent:
@danielcodes
danielcodes / solve.py
Created Apr 2, 2020
Heapify and heapsort
View solve.py
# implement a priority queue
# specifically heapify part
def heapify(A, i, size):
# given a node index and upper bound
# sinks value down until heap invariant is met
while i < size:
index = i
left = 2*i + 1
@danielcodes
danielcodes / solve.py
Last active Mar 28, 2020
323. Number of Connected Components in an Undirected Graph
View solve.py
from collections import deque, defaultdict
# 323. Number of Connected Components in an Undirected Graph
def solve(n, edges):
def bfs(i, adj, visited):
q = deque()
q.append(i)
@danielcodes
danielcodes / solve.py
Last active Mar 27, 2020
253. Meeting rooms ii
View solve.py
from heapq import heapify, heappush, heappop
# 253. Meeting rooms ii
def solve(ints):
if not ints:
return True
ints.sort(key=lambda x: x[0])
@danielcodes
danielcodes / solve.py
Created Mar 27, 2020
252. Meeting rooms
View solve.py
# 252. Meeting rooms
def solve(ints):
# alternate approach is to check current with next
# in this case iteration stops on the second to last interval
if not ints:
return True
@danielcodes
danielcodes / solve.py
Created Mar 22, 2020
395. Longest Substring with At Least K Repeating Characters
View solve.py
from collections import Counter
def solve_1(s, k):
# the one i came up with
chars = Counter()
start = 0
ans = ''
ans_len = float('-inf')
View gist:8e6ee3eea155d9e6bcd191e8f7bbab6d
upstream app_server {
server unix:/home/daniel/run/gunicorn.sock fail_timeout=0;
}
server {
listen 80;
root /home/daniel/voting_app/client/build;
server_name <your_server_ip>;
index index.html index.htm;
@danielcodes
danielcodes / migrate-django.md
Created Mar 3, 2018 — forked from sirodoht/migrate-django.md
How to migrate Django from SQLite to PostgreSQL
View migrate-django.md

How to migrate Django from SQLite to PostgreSQL

Dump existing data:

python3 manage.py dumpdata > datadump.json

Change settings.py to Postgres backend.

Make sure you can connect on PostgreSQL. Then:

You can’t perform that action at this time.