Skip to content

Instantly share code, notes, and snippets.

Avatar
🍊
workin' goodly

Gianni Chiappetta gf3

🍊
workin' goodly
View GitHub Profile
@gf3
gf3 / iTunes.swift
Created Aug 29, 2017
iTunes ScriptingBridge from Swift
View iTunes.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 Aug 14, 2019
NSImageView with rounded corners
View roundedCorners.swift
// XCode 8.3
// Swift 3.1
import Cocoa
class SomeViewController: NSViewController {
@IBOutlet weak var artwork: NSImageView!
override func viewDidLoad() {
super.viewDidLoad()
View rename.vim
" 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 Dec 19, 2016
UUIDs ES6
View uuid.js
/**
* 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 Apr 4, 2018
Backoff AJAX requests
View backoff-request.js
/**
* @flow
*/
import request from 'lib/request';
type F<T> = (response: T) => bool;
const BACKOFF_MAX = 60; // seconds
const BACKOFF_ATTEMPTS = 60;
View NaturalMotion.swift
//
// NaturalMotion.swift
//
// Created by Maciej Swic on 2014-06-06.
// Released under the MIT license.
//
import UIKit
extension UIView {
View Has weird right-to-left characters.txt
ּ_בּ
בּ_בּ
טּ_טּ
כּ‗כּ
לּ_לּ
מּ_מּ
סּ_סּ
תּ_תּ
٩(×̯×)۶
٩(̾●̮̮̃̾•̃̾)۶
View foo.rb
class Foo
autoload :Bar, 'foo/bar'
autoload :Baz, 'foo/baz'
end
@gf3
gf3 / model.js.coffee
Created Oct 24, 2012
Backbone Model Instance Sharing
View model.js.coffee
@instance_store = {}
class App.Model extends Backbone.Model
cache_enabled: false
cache_key: "id"
constructor: (attr) ->
@on "destroy", @_removeFromStore
View point.coffee
# ### 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)