Skip to content

Instantly share code, notes, and snippets.

View spnkr's full-sized avatar

Will Jessop spnkr

  • New York, NY
View GitHub Profile
@spnkr
spnkr / touch_id.rb
Created October 8, 2015 07:59 — forked from evansobkowicz/touch_id.rb
RubyMotion Touch ID
# Call touch_id_authenticate
def touch_id_authenticate
context = LAContext.alloc.init
auth_error = nil
reason = 'Authenticate using your fingerprint'
if context.canEvaluatePolicy(LAPolicyDeviceOwnerAuthenticationWithBiometrics, error: auth_error)
context.evaluatePolicy(LAPolicyDeviceOwnerAuthenticationWithBiometrics, localizedReason: reason, reply: lambda do |success, error|
@spnkr
spnkr / gist:a7992789aef1253cab6e
Created March 18, 2016 14:25 — forked from seanlilmateus/gist:3187192
How to use Obj-C with MacRuby/Rubymotion

Using Obj-C with MacRuby/Rubymotion

This little post aims to help you to translate Objective-C Blocks into Ruby blocks. Let's start by taking a look at few examples of iOS API call where blocks are used for animations and enumeration

Ruby Lambda Syntaxes:

Im Rubymotion and MacRuby you can use all the Ruby Lambda syntaxes that are:

block = lambda { |param|  ... }
@spnkr
spnkr / strip-emoji.rb
Created April 6, 2016 09:06 — forked from adamlwatson/strip-emoji.rb
Strip emoji
# this scrubs emoji sequences from a string - i think it covers all of them
def strip_emoji ( str )
str = str.force_encoding('utf-8').encode
clean_text = ""
# emoticons 1F601 - 1F64F
regex = /[\u{1f600}-\u{1f64f}]/
clean_text = str.gsub regex, ''
@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 / 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 / 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 / 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
// 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 / CoreDataContextObserver.swift
Last active August 5, 2020 15:51 — forked from m1entus/CoreDataContextObserver.swift
CoreDataContextObserver
//
// CoreDataContextWatcher.swift
// ContextWatcher
//
// Created by Michal Zaborowski on 10.05.2016.
// Copyright © 2016 Inspace Labs Sp z o. o. Spółka Komandytowa. All rights reserved.
//. v4
import Foundation
import CoreData