Skip to content

Instantly share code, notes, and snippets.

View spnkr's full-sized avatar

Will Jessop spnkr

  • New York, NY
View GitHub Profile

Keybase proof

I hereby claim:

  • I am spnkr on github.
  • I am willjessop (https://keybase.io/willjessop) on keybase.
  • I have a public key ASBc9HbuOaYcw6McQU4go0Uo7hsSZWAM8WN9doVRuv2DEwo

To claim this, I am signing this object:

// Basically, these are if and else statements respectively
// without the opposite clause
func when(_ test: @autoclosure () -> Bool, action: () -> ()) {
if test() { action() }
}
func unless(_ test: @autoclosure () -> Bool, action: () -> ()) {
if !test() { action() }
}
@spnkr
spnkr / YLColor.swift
Created May 20, 2019 21:50 — forked from yannickl/YLColor.swift
Hex string <=> UIColor conversion in Swift
import Foundation
import UIKit
extension UIColor {
convenience init(hexString:String) {
let hexString:NSString = hexString.stringByTrimmingCharactersInSet(NSCharacterSet.whitespaceAndNewlineCharacterSet())
let scanner = NSScanner(string: hexString)
if (hexString.hasPrefix("#")) {
scanner.scanLocation = 1
@spnkr
spnkr / AppDelegate.swift
Created February 13, 2019 06:45
#blog #AppDelegate
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
_ = coreDataStack.mainContext
self.window = UIWindow(frame: UIScreen.main.bounds)
let loadingViewController = LoadingViewController()
loadingViewController.coreDataStack = coreDataStack
self.window?.rootViewController = loadingViewController
self.window?.makeKeyAndVisible()
app.window = self.window
return true
}
@spnkr
spnkr / application.html.erb
Created February 3, 2019 06:48
Using Google Analytics with Rails 5 and Turbolinks 5. This code is taken from the conversation between @preetpalS and @packagethief on https://github.com/turbolinks/turbolinks/issues/73.
<%# Put this code snippet between the <head></head>-tags in your application layout and %>
<%# replace 'UA-XXXXXXXX-X' with your own unique Google Analytics Tracking ID %>
<%# ... %>
<head>
<%# ... %>
<% if Rails.env.production? %>
<script type="text/javascript">
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
@spnkr
spnkr / psn.rb
Created December 4, 2018 03:05
Ruby PSN API
class _PSN
include HTTParty
attr_accessor :oauth, :error, :npsso, :grant_code, :refresh_token,
:email, :password, :ticket_uuid, :code
ACTIVITY_URL = "https://activity.api.np.km.playstation.net/activity/api/v1/users/"
OAUTH_URL = "https://auth.api.sonyentertainmentnetwork.com/2.0/oauth/token"
SSO_URL = "https://auth.api.sonyentertainmentnetwork.com/2.0/ssocookie"
CODE_URL = "https://auth.api.sonyentertainmentnetwork.com/2.0/oauth/authorize"
@spnkr
spnkr / firebase find invalid keys.rb
Created July 7, 2018 19:39
Find invalid JSON keys for Firebase import
#sometimes when you try to import a json file to firebase via the console, firebase says "invalid keys" (If you create your own keys, they must be UTF-8 encoded, can be a maximum of 768 bytes, and cannot contain ., $, #, [, ], /, or ASCII control characters 0-31 or 127.) This script will print out the invalid keys so you can manually fix them.
#useful if you have a giant firebase json file not generated from another db.
#Caveat: quick and dirty, only goes a few levels deep. theoretically you could use recursion to go n-levels deep, but I didn't need this for my use case.
#Caveat: doesn't check for utf-8 encoding, or ASCII control characters 0-31 and 127.
require 'json'
@spnkr
spnkr / YouTube API — getting video thumbnail
Created January 27, 2018 11:26 — forked from protrolium/YouTube API — getting video thumbnail
YouTube API — getting video thumbnail
Each YouTube video has 4 generated images. They are predictably formatted as follows:
http://img.youtube.com/vi/<insert-youtube-video-id-here>/0.jpg
http://img.youtube.com/vi/<insert-youtube-video-id-here>/1.jpg
http://img.youtube.com/vi/<insert-youtube-video-id-here>/2.jpg
http://img.youtube.com/vi/<insert-youtube-video-id-here>/3.jpg
The first one in the list is a full size image and others are thumbnail images. The default thumbnail image (ie. one of 1.jpg, 2.jpg, 3.jpg) is:
http://img.youtube.com/vi/<insert-youtube-video-id-here>/default.jpg
@spnkr
spnkr / YouTube API — getting video thumbnail
Created January 27, 2018 11:26 — forked from protrolium/YouTube API — getting video thumbnail
YouTube API — getting video thumbnail
Each YouTube video has 4 generated images. They are predictably formatted as follows:
http://img.youtube.com/vi/<insert-youtube-video-id-here>/0.jpg
http://img.youtube.com/vi/<insert-youtube-video-id-here>/1.jpg
http://img.youtube.com/vi/<insert-youtube-video-id-here>/2.jpg
http://img.youtube.com/vi/<insert-youtube-video-id-here>/3.jpg
The first one in the list is a full size image and others are thumbnail images. The default thumbnail image (ie. one of 1.jpg, 2.jpg, 3.jpg) is:
http://img.youtube.com/vi/<insert-youtube-video-id-here>/default.jpg
@spnkr
spnkr / IRB Context
Created December 30, 2017 02:12
IRB Context
# frozen_string_literal: false
#
# irb/context.rb - irb context
# $Release Version: 0.9.6$
# $Revision$
# by Keiju ISHITSUKA([email protected])
#
# --
#
#