Skip to content

Instantly share code, notes, and snippets.

View gf3's full-sized avatar
🍊
workin' goodly

Gianni Chiappetta gf3

🍊
workin' goodly
View GitHub Profile
@gf3
gf3 / iTunes.swift
Created August 29, 2017 18:50
iTunes ScriptingBridge from Swift
import AppKit
import ScriptingBridge
@objc public protocol SBObjectProtocol: NSObjectProtocol {
func get() -> Any!
}
@objc public protocol SBApplicationProtocol: SBObjectProtocol {
func activate()
var delegate: SBApplicationDelegate! { get set }
@gf3
gf3 / roundedCorners.swift
Last active August 14, 2019 14:43
NSImageView with rounded corners
// XCode 8.3
// Swift 3.1
import Cocoa
class SomeViewController: NSViewController {
@IBOutlet weak var artwork: NSImageView!
override func viewDidLoad() {
super.viewDidLoad()
@gf3
gf3 / rename.vim
Created May 2, 2017 14:04
Vim Rename
" Rename buffer (:Rename) {{{
function! s:RenameBuffer(name)
silent! execute 'saveas! ' . a:name
let l:old_buffer = bufnr("#")
let l:old_filename = expand("#:t")
let l:new_buffer = bufnr("%")
let l:new_filename = expand("%:t")
silent! execute '!rm ' . shellescape(expand("#"), 1)
silent! execute 'bd' l:old_buffer
echom 'Renamed `' . l:old_filename . '` to `' . l:new_filename . '`'
@gf3
gf3 / uuid.js
Created December 19, 2016 16:37
UUIDs ES6
/**
* Convert a number or array of integers to a string of padded hex octets.
*/
function asHex(value: Array<number> | Uint8Array): string {
return Array.from(value).map(i => ('00' + i.toString(16)).slice(-2)).join('');
}
/**
* Attempt to securely generate random bytes/
*/
@gf3
gf3 / backoff-request.js
Last active April 4, 2018 02:02
Backoff AJAX requests
/**
* @flow
*/
import request from 'lib/request';
type F<T> = (response: T) => bool;
const BACKOFF_MAX = 60; // seconds
const BACKOFF_ATTEMPTS = 60;
@gf3
gf3 / NaturalMotion.swift
Created February 29, 2016 19:35 — forked from maciekish/NaturalMotion.swift
Easy UIInterpolatingMotionEffect. Learn more: http://hack.swic.name/easy-uiinterpolatingmotioneffect
//
// NaturalMotion.swift
//
// Created by Maciej Swic on 2014-06-06.
// Released under the MIT license.
//
import UIKit
extension UIView {
ּ_בּ
בּ_בּ
טּ_טּ
כּ‗כּ
לּ_לּ
מּ_מּ
סּ_סּ
תּ_תּ
٩(×̯×)۶
٩(̾●̮̮̃̾•̃̾)۶
@gf3
gf3 / foo.rb
Created January 22, 2013 22:17 — forked from stouset/foo.rb
class Foo
autoload :Bar, 'foo/bar'
autoload :Baz, 'foo/baz'
end
@gf3
gf3 / model.js.coffee
Created October 24, 2012 19:08
Backbone Model Instance Sharing
@instance_store = {}
class App.Model extends Backbone.Model
cache_enabled: false
cache_key: "id"
constructor: (attr) ->
@on "destroy", @_removeFromStore
# ### Point.angleForCircle( origin, point ) -> Number
#
# * **origin** ( `Point` ): Origin of circle.
# * **point** ( `Point` ): Point to find angle of.
#
# Get the angle (in degrees) of a point for a given origin of a circle.
Point.angleForCircle = (origin, point) ->
x = origin.x - point.x
y = origin.y - point.y
r = Math.sqrt Math.pow(x, 2) + Math.pow(y, 2)