Skip to content

Instantly share code, notes, and snippets.

@kevincolten
kevincolten / gist:8853141
Created February 6, 2014 21:46
listing all (mysql) processes and killing them
$ ps aux | grep mysql
$ sudo kill -9 629 513 #1, 5, 9 (varying levels of process killing)
class ApplicationController < ActionController::Base
protect_from_forgery
before_filter :cor
def cor
headers["Access-Control-Allow-Origin"] = "http://localhost:8000"
headers["Access-Control-Allow-Methods"] = %w{GET POST PUT DELETE}.join(",")
headers["Access-Control-Allow-Headers"] = %w{Origin Accept Content-Type X-Requested-With X-CSRF-Token}.join(",")
head(:ok) if request.request_method == "OPTIONS"
end
@kevincolten
kevincolten / subl.sh
Last active August 29, 2015 14:00
Launch Sublime Text from terminal
sudo ln -s /Applications/Sublime\ Text.app/Contents/SharedSupport/bin/subl /usr/bin/subl
@kevincolten
kevincolten / setup.sh
Last active August 29, 2015 14:07
When Setting Up a New Mac
# Check for Homebrew,
# Install if we don't have it
if test ! $(which brew); then
echo "Installing homebrew..."
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
fi
# Update homebrew recipes
brew update
@kevincolten
kevincolten / phpcs-newer.sh
Created January 27, 2015 22:16
Run PHP_CodeSniffer on files with uncommitted changes
if [ "$(git diff --name-only master --diff-filter=AMR | grep -Ei "^.*app\/(models|controllers)\/.*\.php$")" ]; then vendor/bin/phpcs $(git diff --name-only master --diff-filter=AMR | grep -Ei "^.*app\/(models|controllers)\/.*\.php$") --standard=PSR2; fi
@kevincolten
kevincolten / sparkMySQL.scala
Created June 7, 2015 20:07
Import MySQL into Spark
SPARK_CLASSPATH=../mysql-connector-java-5.1.35/mysql-connector-java-5.1.35-bin.jar bin/spark-shell
val jdbcDF = sqlContext.load("jdbc", Map(
"url" -> "jdbc:mysql://localhost:8889/employees?user=root&password=root",
"dbtable" -> "(SELECT employees.*, departments.*, salaries.salary, titles.title FROM employees JOIN dept_emp ON dept_emp.emp_no = employees.emp_no JOIN departments ON departments.dept_no = dept_emp.dept_no JOIN dept_manager ON dept_manager.emp_no = employees.emp_no JOIN salaries ON salaries.emp_no = employees.emp_no JOIN titles ON employees.emp_no = titles.emp_no) AS employees",
"driver" -> "com.mysql.jdbc.Driver",
"partitionColumn" -> "emp_no",
"lowerBound" -> "10001",
"upperBound" -> "499999",
"numPartitions" -> "10"
@kevincolten
kevincolten / merge_weekly_monthy.py
Last active August 29, 2015 14:23
Download Google Trends
import csv
from collections import deque
with open('weekly_stock_trends.csv', 'rb') as f:
reader = csv.reader(f)
weekly_trends = list(reader)
headers = weekly_trends.pop(0)
new_headers = []
@kevincolten
kevincolten / ocean_plot.py
Last active August 29, 2015 14:24
Ocean Plot
from bokeh.embed import components
from bokeh.models import AjaxDataSource, Callback, Slider
from bokeh.plotting import figure, output_file, show, vplot
from jinja2 import Template
import webbrowser
import os
import six
source = AjaxDataSource(
data_url='http://54.80.255.253:5000/subsample/0/180/0/360/350/800/0',
@kevincolten
kevincolten / post.md
Last active August 29, 2015 14:25
@post Backbone + React: or, How I Came to Stop Looking for an Example and Built My Own

This tutorial came out of many frustrating google searches trying to find a decent end-to-end boilerplate example of incorporating React as the view component in Backbone. The three components I wanted in a tutorial were:

  1. Build something more than a single page TODO
  2. Involved routing and controllers
  3. Included a build process using a modern build tool
  4. Optimization and source-mapping
  5. Done in an organized manner with descriptive naming patterns

What we'll be building in this tutorial is a basic blog viewer. The source can be found here and the finished product can be found here. When complete, we'll be able to write the blog post in markdown in a gist with the title starting with a key word (ex. @post Here's My Post Title!) and display it in all its html glory.

So let's get started.

@kevincolten
kevincolten / protocol.md
Last active August 29, 2015 14:25
Tornado Sandbox

ClientDataStore operations

Stores actual columns of data on the client. Used by lightweight "data source" models. Supports performing the following CRUD operations.

  • create new columns

  • replace all columns