Skip to content

Instantly share code, notes, and snippets.

View stevenschobert's full-sized avatar

Steven Schobert stevenschobert

View GitHub Profile
@stevenschobert
stevenschobert / disable_press_and_hold.sh
Created February 17, 2014 16:43
Turn off Apples "Press and Hold" keyboard option (for alt characters). Useful if you want key-repeat for letter characters.
# app-specific. replace BUNDLE_NAME with app bundle (ex: com.sublimetext.2)
defaults write BUNDLE_NAME ApplePressAndHoldEnabled -bool false
# global
defaults write -g ApplePressAndHoldEnabled -bool false
@stevenschobert
stevenschobert / Gemfile
Created February 20, 2014 19:57
Starter set of files for a simple rack app. Useful for quickly deploying static sites to something like Heroku, or using Pow for editing static sites.
source 'https://rubygems.org'
ruby '2.0.0'
gem 'rack'
@stevenschobert
stevenschobert / filepath_regex
Last active August 29, 2015 13:58
My take on a filepath testing regular experession. Requires a relative or absolute path, and an extension. Excludes plain filenames.
^[\.+]*\/+.*\.[a-zA-Z0-9]+$
# Matches
/Users/stevenschobert/Documents/project/tmp/tmp-8205.txt
../somepath.txt
./sompat/h.d
./Something with spaces/word.txt
# Does not match
../sompath
@stevenschobert
stevenschobert / remove_not_created_today.sh
Created April 23, 2014 16:11
Remove files from directory not created today
grep -l -R -v "$(date '+%b %e')" * | xargs rm
@stevenschobert
stevenschobert / covert_dir_haml.sh
Created May 5, 2014 20:25
Convert a directory of Haml files.
find in/ -name '*.haml' | xargs basename -s .haml | xargs -I % bundle exec haml in/%.haml out/%.html
@stevenschobert
stevenschobert / crashlytics_run_optional.sh
Created October 7, 2014 21:15
Optional Crashlytics script for Xcode
testCrashlyticsPresent='try\n set crashlytics to application "Crashlytics"\n properties of crashlytics\non error errorMessage\n if errorMessage contains "application" then\n error\n else\n return true\n end if\nend try\n'
if $(echo $testCrashlyticsPresent | /usr/bin/osascript 2>/dev/null); then
./Crashlytics.framework/run CRASHLYTICS_KEY
else
echo "Crashlytics isn't installed. Skipping."
exit 0
fi
@stevenschobert
stevenschobert / app_exists.scpt
Created October 7, 2014 21:16
Tests if an application is installed on your system
try
set targetApp to application "APPNAME"
properties of targetApp
on error errorMessage
if errorMessage contains "application" then
error
else
return true
end if
end try
@stevenschobert
stevenschobert / request.js
Created December 2, 2014 20:02
Some bare-bones Request/Response prototypes for JavaScript. Wraps XMLHttpRequest.
/**
* Request class for making HTTP requests.
*
* new Request('http://api.com', {
* method: 'get',
* headers: {}
* }).send(function(res) {});
*/
function Request(url, opts) {
opts = opts || {};
@stevenschobert
stevenschobert / camel_case.swift
Last active July 30, 2023 13:09
Camel-case a string in Swift
func camelCaseString(source: String) -> String {
if contains(source, " ") {
let first = source.substringToIndex(advance(source.startIndex, 1))
let cammel = NSString(format: "%@", (source as NSString).capitalizedString.stringByReplacingOccurrencesOfString(" ", withString: "", options: nil, range: nil)) as String
let rest = dropFirst(cammel)
return "\(first)\(rest)"
} else {
let first = (source as NSString).lowercaseString.substringToIndex(advance(source.startIndex, 1))
let rest = dropFirst(source)
return "\(first)\(rest)"
@stevenschobert
stevenschobert / instafeed_wrap_fourth.js
Created December 18, 2014 18:32
Instafeed.js - Wrap every 4th item with a tag
var count = 0;
var feed = new Instafeed({
filter: function(image) {
count += 1;
if (count % 4 === 0) {
image.customTagOpen = '<div>';
image.customTagClose = '</div>';
} else {
image.customTagOpen = '';