Skip to content

Instantly share code, notes, and snippets.

@woodphil
woodphil / file-reset.js
Created February 10, 2016 21:06
js-reset-file-upload-form
document.getElementById("upload-files").value = "";
@woodphil
woodphil / vim_cmd.vim
Last active May 30, 2016 18:32
Useful vim commands
:set ft=filetype
:set relativenumber
@woodphil
woodphil / permutation based questions
Created January 8, 2016 06:28
Dynamic Programming tip #1
if you move 0 to index i there results in 2 cases:
i moved to 0: then the problem is reduced to n-2 (2 elements have swapped and are guaranteed to be in different positions)
i moved to somewhere else: problem is reduced to n-1 (n-1 slots left)
@woodphil
woodphil / python-sqlite-abs-path.py
Created January 5, 2016 23:48
Python sqlite absolute path to database
package_dir = os.path.abspath(os.path.dirname(__file__))
db_dir = os.path.join(package_dir, 'nd_slack.db')
# NEED 4 /'s to specify absolute for sqlalchemy!
# ex: sqlite:////asdfaijegoij/aerga.db
# NEED 3 /'s for relative paths
# path has a / at the beginning so we have 3 here
SQLITE_DB = ''.join(['sqlite:///', db_dir])
@woodphil
woodphil / sockets.md
Created January 5, 2016 19:35
Notes on sockets in general

Two Types of Socket:

UNIX Socket: Communicate between processes within a single local host. No networking capabilities

Berkeley Socket: Communicate between hosts via ports. Creating a Berkeley Socket creates a port and binds to it and the OS subsequently redirects all packages to that port to the bound process.

@woodphil
woodphil / curl.md
Created January 5, 2016 19:00 — forked from btoone/curl.md
A curl tutorial using GitHub's API

Introduction

An introduction to curl using GitHub's API

The Basics

Makes a basic GET request to the specifed URI

curl https://api.github.com/users/caspyin
@woodphil
woodphil / headers.rb
Created January 5, 2016 18:59
Ruby uri requesting example
require "net/http"
require "uri"
uri = URI.parse("http://google.com/")
http = Net::HTTP.new(uri.host, uri.port)
request = Net::HTTP::Get.new(uri.request_uri)
request["User-Agent"] = "My Ruby Script"
request["Accept"] = "*/*"
@woodphil
woodphil / python-decorator.py
Created January 4, 2016 22:23
Python Decorator example
def exception_catcher(func):
def inner_func(*args, **kwargs):
try:
func(*args, **kwargs)
return True, None
except Exception as inst:
return False, inst
return inner_func
@exception_catcher
@woodphil
woodphil / flask-json-form-request.py
Created January 4, 2016 21:39
Python-Flask Handle json/form request data
if request.headers['Content-Type'] == 'application/json':
request_data = request.get_json()
user_id = request_data['user_id']
msg = request_data['message']
else:
user_id = request.form['user_id']
msg = requ