Skip to content

Instantly share code, notes, and snippets.

View jwhitley's full-sized avatar
🏝️
balearic

John Whitley jwhitley

🏝️
balearic
View GitHub Profile
@pstuifzand
pstuifzand / just-one-space.vim
Created August 5, 2009 09:29
Just one space function for vim
" Replace many spaces with one in Vim
" With help from Al: http://stackoverflow.com/questions/1228100/substituting-zero-width-match-in-vim-script
function JustOneSpace()
" Get the current contents of the current line
let current_line = getline(".")
" Get the current cursor position
let cursor_position = getpos(".")
### Rakefile
task :template do
require 'yaml'
require 'erb'
base = File.join(File.dirname(__FILE__), 'config')
source = File.join(base, 'dna.json.erb')
target = File.join(base, 'dna.json')
recipes = ENV['recipe'] || %w(packages users gems)
@uasi
uasi / vim.rb
Created November 30, 2010 16:46
Vim formula for Homebrew (EDIT: recent versions of official Homebrew distribution includes one)
require 'formula'
class Vim < Formula
homepage 'http://www.vim.org/'
url 'ftp://ftp.vim.org/pub/vim/unix/vim-7.3.tar.bz2'
head 'https://vim.googlecode.com/hg/'
sha256 '5c5d5d6e07f1bbc49b6fe3906ff8a7e39b049928b68195b38e3e3d347100221d'
version '7.3.682'
def features; %w(tiny small normal big huge) end
@blambeau
blambeau / destr.rb
Created November 22, 2011 09:00
Fun destructuring in Ruby 1.9
class Hash
def with(&block)
block.call *block.parameters.map{|x| self[x.last]}
end
end
# Example
h = {:name => "blambeau", :hobby => "ruby"}
@jrburke
jrburke / builder.js
Created December 1, 2011 19:07
Multiple single file builds using one "build script" for requirejs optimizer
//Load the requirejs optimizer
var requirejs = require('./path/to/r.js'),
//Set up basic config, include config that is
//common to all the optimize() calls.
basConfig = {
baseUrl: './some/path',
paths: {
//whatever is neded globally.
}
};
@jrburke
jrburke / amdconfig.md
Created January 18, 2012 00:52
Rough draft of common config understood by loaders

Attempt to list some possible standard AMD loader configuration values.

An AMD loader is not required to implement all of these configuration values, but if it does provide a capability that is satisfied by these configuration values, it should use these configuration values and structures.

baseUrl

String: Indicates the root used for ID-to-path resolutions. Relative paths are relative to the current working directory. In web browsers, the current working directory is the directory containing the web page running the script.

require 'minitest/unit'
require 'celluloid'
module MiniTest
module Celluloid
class Runner < MiniTest::Unit
def _run_suites(suites, type)
futures = suites.map do |suite|
::Celluloid::Future.new { _run_suite suite, type }
@robjwells
robjwells / Restart in Windows.applescript
Last active October 10, 2015 11:17
Quickly restart your Mac into Windows
set deviceID to (do shell script "diskutil list | awk '/YourBootcampPartition/ {print $NF}'")
do shell script "bless -device /dev/" & deviceID & " -legacy -setBoot -nextonly" ¬
with administrator privileges
tell application "Finder" to restart
@endash
endash / gist:acda517225dc9f4bc9db
Last active September 27, 2019 06:10
Photoshop style gradients in Core Graphics via use of CGShader (with thanks to @jernejstrasner, see his explanation of why your gradients might not look how your designers intended http://jernejstrasner.com/2014/01/09/smooth-gradients-ios.html) ⚠️ see comments for notes
func SineEaseInOutLinearAverage(x: Double) -> Double {
var easeInOutSine = ((cos(M_PI * x) - 1) / -2)
return (easeInOutSine + x) / 2
}
func ShadingFunctionCreate(startColor: NSColor, _ endColor: NSColor, _ slopeFunction: (Double) -> Double) -> (UnsafePointer<CGFloat>, UnsafeMutablePointer<CGFloat>) -> Void {
return { inData, outData in
let q = CGFloat(slopeFunction(Double(inData[0])))
outData[0] = startColor.redComponent + (endColor.redComponent - startColor.redComponent) * q
outData[1] = startColor.greenComponent + (endColor.greenComponent - startColor.greenComponent) * q
@kizzx2
kizzx2 / hammerspoon-move-resize.lua
Last active December 19, 2022 06:47
Hammerspoon script to move/resize window under cursor
-- Inspired by Linux alt-drag or Better Touch Tools move/resize functionality
function get_window_under_mouse()
-- Invoke `hs.application` because `hs.window.orderedWindows()` doesn't do it
-- and breaks itself
local _ = hs.application
local my_pos = hs.geometry.new(hs.mouse.getAbsolutePosition())
local my_screen = hs.mouse.getCurrentScreen()