Skip to content

Instantly share code, notes, and snippets.

View kvchen's full-sized avatar

Kevin Chen kvchen

View GitHub Profile
@kvchen
kvchen / facetla_scraper.py
Last active January 3, 2016 07:29
scraper for facet.la
import requests
import shutil
from bs4 import BeautifulSoup
BASE_URL = "http://www.facet.la/wallpapers/"
r = requests.get(BASE_URL)
soup = BeautifulSoup(r.text)
# Loop through all images on the base thumbnail site
@kvchen
kvchen / wordmaster.py
Last active August 29, 2015 14:03
Wordmaster Solver
#!/usr/bin/env python
import string
DICT_FILE = '/usr/share/dict/words'
def get_matches(word, guess):
word_set = set([c for c in word])
guess_set = set([c for c in guess])
return len(word_set.intersection(guess_set))
@kvchen
kvchen / iterative_hanoi.py
Last active August 29, 2015 14:03
Iterative Towers of Hanoi
# !/usr/bin/env python
# coding: utf-8
# http://en.wikipedia.org/wiki/Tower_of_Hanoi#Binary_solution
def iterative_hanoi(n):
# Optimal play will result in (2^n)-1 moves. This is a pretty fun proof!
total_moves = pow(2, n) - 1
for i in range(total_moves):
start = (i & i+1) % 3
end = ((i | i+1)+1) % 3
@kvchen
kvchen / gist:57d0e27af7969b962118
Created November 10, 2014 22:04
Newline Fixer
"""Fixes newline endings created in Windows. Run in Unix."""
for i in range(1, 17):
output_path = '../output{}.txt'.format(i)
with open(output_path, 'r') as output_file:
sequence = output_file.readline().strip()
with open(output_path, 'w') as output_file:
output_file.write(sequence + '\n')
Here's the current folder hierarchy:
- run.py
- util/
- __init__.py
- entry.py
- winrate.py
Let's say winrate.py straight up imports entry:
def copy(lst):
"""Returns a copy of the linked list."""
if lst.rest is Link.empty:
return Link(lst.first)
else:
return Link(lst.first, copy(lst.rest))
def repeat(lst, n):
if n == 0:
return Link.empty
from bs4 import BeautifulSoup
import json
def main():
with open('messages.htm', 'r') as infile:
soup = BeautifulSoup(infile)
bchus = []
@kvchen
kvchen / gist:1b843ba2e91c26538a1e
Last active September 22, 2017 10:05
Installing SQLite

Installing SQLite

The simplest way to start using SQLite is to download a precompiled binary from the

The latest version of SQLite at the time of writing is 3.8.9, but you can check for additional updates on the SQLite download page.

Windows

import string
def fix(s):
return s.strip().lower().translate(string.maketrans('', ''), string.punctuation)
print(fix(" He@#@LL%^O WorL@#D@$"))
Promise = require 'bluebird'
bcrypt = Promise.promisifyAll(require 'bcrypt')
bookshelf = require 'app/utils/db'
logger = require 'app/utils/logger'
User = bookshelf.Model.extend
tableName: 'users'
hasTimestamps: ['createdAt', 'updatedAt']