Skip to content

Instantly share code, notes, and snippets.

View stevenschobert's full-sized avatar

Steven Schobert stevenschobert

View GitHub Profile
@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 / ntlm_authentication_example.swift
Created June 17, 2016 14:00
Example of NTLM authentication in iOS using NSURLSession
import UIKit
class ViewController: UIViewController {
@IBOutlet weak var execButton: UIButton!
var username: String? = nil
var password: String? = nil
lazy var conn: NSURLSession = {
@stevenschobert
stevenschobert / footer_copyright.haml
Created February 6, 2016 06:14
Ruby/Haml snippet for an auto-updating copyright notice. Good for footers and such.
@stevenschobert
stevenschobert / load_remote_content_mail_dot_app.scpt
Last active January 12, 2022 11:19
Apple Script to click the "Load Remote Content" button. I like to disable all remote content in Mail.app, and then bind this script to a keyboard shortcut using Keyboard Maestro. https://www.keyboardmaestro.com
tell application "System Events" to tell process "Mail"
set mainWindow to a reference to the first window
set rootSplitter to a reference to the first splitter group of the mainWindow
set firstSplitter to a reference to the last splitter group of the rootSplitter
set scrollArea to a reference to the last scroll area of the firstSplitter
set scrollGroup to a reference to the first group of the scrollArea
if number of groups of the scrollGroup is greater than 1 then
set maybeRemoteContentGroup to a reference to the first group of the scrollGroup
@stevenschobert
stevenschobert / centos_7_setup.md
Last active December 29, 2021 01:38
My setup guide for CentOS 7

Start

Add non-root user

adduser deploy
passwd deploy

Update system packages

@stevenschobert
stevenschobert / safari_find_or_open_url.scpt
Created June 1, 2016 22:43
AppleScript to find existing tab with URL, or open a new one.
tell application "Safari"
set topWindows to every window whose name is not ""
set numWindows to the number of topWindows
set didFind to false
set targetUrl to "http://localhost:3000/"
repeat with x from 1 to numWindows
set numTabs to the number of tabs in window x
repeat with y from 1 to numTabs
set tabUrl to the URL of tab y of window x
@stevenschobert
stevenschobert / extend.js
Created December 30, 2014 15:12
Object extending - supports N... arguments
function extend() {
var args = [].slice.call(arguments);
args[0] = (typeof args[0] === 'object') ? args[0] : {};
for (var i=1; i<args.length; i++) {
if (typeof args[i] === 'object') {
for (var key in args[i]) {
if (args[i].hasOwnProperty(key)) {
args[0][key] = args[i][key];
}
}
@stevenschobert
stevenschobert / api_client_standalone.rb
Last active February 2, 2017 19:17
Standalone Net::HTTP wrapper class for interfacing with JSON APIs. I typically use this when I have many classes that need to talk to different APIs in a project. Otherwise if I'm building a single API client gem, I sometimes use this instead: https://gist.github.com/stevenschobert/8df1dc08a96ba0ecc274
class ApiClient
attr_accessor :base_url
attr_accessor :default_headers
attr_accessor :default_params
attr_accessor :basic_auth
attr_reader :body
def initialize(base_url:, headers: {}, params: {})
@base_url = base_url
@stevenschobert
stevenschobert / dropbox_backup.sh
Last active August 26, 2016 15:15
My go-to hacky backup solutions: gzip directories up to Dropbox! Uses https://github.com/andreafabrizi/Dropbox-Uploader
#!/usr/bin/env bash
MAX_NUM_BACKUPS=10
DB_LOCATION=/root/dropbox_uploader.sh
DB_CONFIG=/root/.dropbox_uploader
BACKUP_FILENAME=ss_ranch_bkup
BKP_DIRS="/home/docker/rancher /home/docker/nginx"
EXCLUDE_DIRS="/home/docker/nginx/ssl"
TMP_DIR="/tmp/"
@stevenschobert
stevenschobert / log.js
Last active August 19, 2016 05:31
My personal Log utility. Has option to set log level.
var Log = {
_levelInt: function levelInt() {
return this._levels.indexOf(this.level);
},
_intForLevel: function intForLevel(level) {
return this._levels.indexOf(level);
},
_logForLevel: function logForLevel() {
if (!console) { return; }