Skip to content

Instantly share code, notes, and snippets.

View danielcodes's full-sized avatar

Daniel Chia danielcodes

View GitHub Profile
@danielcodes
danielcodes / solve.py
Created March 22, 2020 05:43
395. Longest Substring with At Least K Repeating Characters
from collections import Counter
def solve_1(s, k):
# the one i came up with
chars = Counter()
start = 0
ans = ''
ans_len = float('-inf')
@danielcodes
danielcodes / gist:8e6ee3eea155d9e6bcd191e8f7bbab6d
Created March 17, 2018 23:09
Nginx config file for Pollster
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 March 3, 2018 19:21 — forked from sirodoht/migrate-django.md
How to migrate Django from SQLite to PostgreSQL

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:

// library class, 2 methods
// find book details by ISBN
// find book by title
// can add more metadata later
function Book(title, author, isbn){
this.title = title;
this.author = author;
this.isbn = isbn;
@danielcodes
danielcodes / minimax.js
Created January 10, 2017 17:48
Minimax implementation
'use strict';
// testing out minimax algorithm on node first before adding it to client side
/*
a recursize algorithm
base cases are end states
1 for a win, 0 for a draw and -1 for a loss
recursive steps
@danielcodes
danielcodes / app.py
Created April 15, 2016 21:40
Flask, messing with file upload
import os
from flask import Flask, request, redirect, url_for
from werkzeug import secure_filename
#create this folder structure, static/uploads
UPLOAD_FOLDER = './static/uploads/'
ALLOWED_EXTENSIONS = set(['txt', 'pdf', 'png', 'jpg', 'jpeg', 'gif'])
app = Flask(__name__)
app.config['UPLOAD_FOLDER'] = UPLOAD_FOLDER
function sym(args) {
//solution with ES6
//instead of doing manual work, make set operations
//combine values
var union = (set1, set2) => new Set([...set1, ...set2]);
//Common values, set1 values, if set2 has them, keep them
var intersection = (set1, set2) => new Set( [...set1].filter(value => set2.has(value)) );
//keep values that are found only in set1
#table formatting example
# lists to create table
header = ['First name', 'Last name']
first = ['Daniel', 'Ronnie', 'Vanessa']
last = ['Chia', 'Hernandez', 'Luka']
# define variables
col_count = 2
col_widths = [10, 9]
@danielcodes
danielcodes / .tmux.conf
Created December 16, 2015 22:45
My .tmux.conf
#set -g default-terminal "screen-256color"
#prefit to ctrl+a
unbind C-b
set -g prefix C-a
# easy-to-remember split pane commands
bind | split-window -h -c "#{pane_current_path}"
bind - split-window -v -c "#{pane_current_path}"
bind c new-window -c "#{pane_current_path}"