Skip to content

Instantly share code, notes, and snippets.

View noahsark769's full-sized avatar

Noah Gilmore noahsark769

View GitHub Profile
@noahsark769
noahsark769 / gist:5448817
Created April 24, 2013 01:11
Can someone tell me why this is failing in seeds.rb, rails 3.2.12? It seems to work in ruby 2.0.0 but not 1.9.3 or 1.9.2. The weird thing is it works in an irb session, but not when rails runs seeds.rb (it gives a syntax error on the first line).
fft_desc = <<fft
FACT!!!: Americans spend 9.4% of their disposable income on food. That is less than any other country in the world.
CONSEQUENCES!!!: Obesity, type II diabetes, commodification of food, factory farming, corn syrup, processing, packaging, pollution, pesticides, fertilizers, and tasteless food-like products.
fft
@noahsark769
noahsark769 / git-fuzzy-co
Created January 14, 2016 00:32
Fuzzy branch checkout with branch name matching
#!/usr/bin/env python
"""
git fuzzy-checkout
Same as `git checkout branch`, but with fuzzy matching if checkout fails.
Turns `git checkout barnch` into `git checkout branch`,
assuming `branch` is a branch.
"""
import difflib
@noahsark769
noahsark769 / blameline.sh
Created January 6, 2017 20:41
Get history of line in file from git
# Usage: blameline <filename> <line number>
function blameline {
cmd="git log -u -L $2,$2:$1"
echo $cmd
$cmd
}
@noahsark769
noahsark769 / .pre-commit-config.yaml
Created March 12, 2018 15:51
Python pre-commit setup
- repo: git://github.com/pre-commit/pre-commit-hooks
sha: v1.2.0
hooks:
- id: check-added-large-files
- id: check-ast
- id: check-case-conflict
- id: check-docstring-first
- id: check-merge-conflict
- id: check-symlinks
- id: double-quote-string-fixer
@noahsark769
noahsark769 / apns.py
Created December 11, 2018 19:40
APNSService for calling APNS
"""Apple Push Notification Service Library.
Documentation is available on the iOS Developer Library:
https://developer.apple.com/library/ios/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/Chapters/ApplePushService.html
This is from django_push_notifications, but I cleaned it up and edited it to
work with custom settings.
"""
import json
@noahsark769
noahsark769 / kth_smallest.py
Created December 18, 2018 04:55
kth smallest
def kthSmallest(root, k):
"""
:type root: TreeNode
:type k: int
:rtype: Optional[int]
"""
def recurse(node, k):
if not node:
return None, k
@noahsark769
noahsark769 / EitherView.swift
Last active February 3, 2019 03:46
UIView subclass which displays one of a given set of views at a time
final class EitherView: UIView {
private let views: [UIView]
init(views: [UIView]) {
self.views = views
super.init(frame: .zero)
}
required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
@noahsark769
noahsark769 / UIColor+Hex.swift
Created February 6, 2019 17:48
Instantiate a UIColor from a hex string with 6 or 8 chars
extension UIColor {
// Adapted from https://gist.github.com/yannickl/16f0ed38f0698d9a8ae7, modified to accept alpha
// values. Works with strings with or without "#", 6 char strings like "a735b5", 8 char strings
// with alpha value like "836be64"
convenience init(hexString: String) {
let hexString = hexString.trimmingCharacters(in: .whitespacesAndNewlines)
let scanner = Scanner(string: hexString)
if (hexString.hasPrefix("#")) {
scanner.scanLocation = 1
@noahsark769
noahsark769 / UIImageView+ColorWheel.swift
Created February 27, 2019 16:47
Get the point on a color wheel image for a given color
extension UIImageView {
func pointOnColorWheel(for color: UIColor) -> CGPoint? {
guard let image = self.image else { return nil }
var hue: CGFloat = 0
var saturation: CGFloat = 0
var brightness: CGFloat = 0
color.getHue(&hue, saturation: &saturation, brightness: &brightness, alpha: nil)
let width = self.frame.size.width
@noahsark769
noahsark769 / README.md
Created March 29, 2019 18:58
Local PSQL configuration for Django projects

I keep forgetting how to do initial local setup of postgres for django projects, so here are the steps I generally follow:

  1. Install postgres locally (for mac I like postgres.app). If you get a return value from which psql, you should be good to go
  2. Set up your local database:
$ psql
postgres=# CREATE USER myproject_user WITH PASSWORD 'myproject_user';
CREATE ROLE
postgres=# CREATE DATABASE myproject_main;