Skip to content

Instantly share code, notes, and snippets.

Avatar
🍊
workin' goodly

Gianni Chiappetta gf3

🍊
workin' goodly
View GitHub Profile
@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()
@gf3
gf3 / Spotify.swift
Created Aug 29, 2017
Spotify ScriptingBridge from Swift
View Spotify.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 / main.rs
Created May 29, 2019
error[E0507]: cannot move out of borrowed content
View main.rs
extern crate unidiff;
use unidiff::PatchSet; // http://messense.github.io/unidiff-rs/unidiff/struct.PatchSet.html
pub struct Printer {
patch_set: PatchSet,
}
impl Printer {
pub fn new(source: &str) -> Self {
@gf3
gf3 / setup.sh
Last active Jan 22, 2019
Neovim config setup
View setup.sh
#!/bin/sh
# Install:
# curl -fsL https://gist.githubusercontent.com/gf3/3d90fd82deaa4cab19fb8d817a370e27/raw/setup.sh | sh
# Directories
mkdir -p ~/.local/share/nvim/{backup,swap,undo}
# Config
curl -fLo ~/.local/share/nvim/site/autoload/plug.vim --create-dirs https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim
@gf3
gf3 / README.md
Last active Jan 22, 2019
Docker: VPN + DNS Proxy + App
View README.md

Docker setup

Using the docker-compose.yml below as a template, replace the webapp section with your application.

VPN setup

Follow the setup guide here: https://github.com/kylemanna/docker-openvpn

Afterwards we'll want to modify the VPN config so that it points to our local DNS proxy.

@gf3
gf3 / html5.vim
Created May 5, 2010 — forked from rcmachado/html5.vim
vim HTML5 Syntax File
View html5.vim
" Vim syntax file
" Language: HTML (version 5)
" Maintainer: Rodrigo Machado <rcmachado@gmail.com>
" URL: http://rm.blog.br/vim/syntax/html.vim
" Last Change: 2009 Aug 19
" License: Public domain
" (but let me know if you liked it :) )
"
" Note: This file just adds the new tags from HTML 5
" and don't replace default html.vim syntax file
@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;
@gf3
gf3 / uuid.ts
Created Feb 20, 2018
Generate a secure RFC4122-compliant v4 UUID
View uuid.ts
/**
* Convert a number or array of integers to a string of padded hex octets.
*/
function asHex(value: number[] | Uint8Array): string {
return Array.from(value).map(i => ('00' + i.toString(16)).slice(-2)).join('');
}
/**
* Attempt to securely generate random bytes/
*/
@gf3
gf3 / email-test.js
Last active Dec 21, 2017
Validate and correct misspelled emails using a fuzzy matcher
View email-test.js
/* eslint-env jasmine */
import { validate, suggest } from './email';
describe('email', () => {
describe('validate', () => {
it('should correctly validate correct email addresses', (done) => {
const promises = [
validate('user@gmail.com'),
validate('user+dix@host.ca'),
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 . '`'