Skip to content

Instantly share code, notes, and snippets.

View rjchatfield's full-sized avatar

Smiley Rob rjchatfield

View GitHub Profile
@rjchatfield
rjchatfield / dotfiles_folder_gen.sh
Created February 21, 2014 12:35
Generates a hidden folder of symlinks to your dotfiles. Open ~/.dotfiles directory in text editor for easy access, without all the other stuff.
#!/bin/bash
mkdir ~/.dotfiles;
cd ~/.dotfiles;
ln -s ../.bash_profile;
ln -s ../.bash_prompt;
ln -s ../.exports;
ln -s ../.aliases;
ln -s ../.functions;
ln -s ../.profile;
ln -s ../.gitconfig;
@rjchatfield
rjchatfield / references.cpp
Created March 4, 2014 12:00
Who needs help with references and dereferencing? I just made this tiny program to help me understand what `int *myInt` meant at different places.
#include <iostream>
using namespace std;
void myFunc(int *r) //-- If you dereference this `r`, you'll get an int
{
cout << " r: " << r << endl; //-- `r` is just a reference
cout << " *r: " << *r << endl; //-- Dereference a reference, gives me an int
}
int main(int argc, const char * argv[])
@rjchatfield
rjchatfield / keyRepeatRateFunction.sh
Last active August 29, 2015 14:01
Simple shell function to speed up the key repeat and key repeat delay. Everyone with a Mac should use this.
# Must log out and log back in for settings to take effect
# $ keyRepeatRate 1 # for fast
# $ keyRepeatRate # for defaults
keyRepeatRate() {
echo
echo "Resetting key repeat settings to default"
echo
@rjchatfield
rjchatfield / lineCount.sh
Last active August 29, 2015 14:01
Count the number of lines of code so you can prove to your manager that you're worth that pay rise
# Count the number of lines of code
lineCount()
{
file_types=(h m hpp cpp java html js css scss py rb php sql)
integer totallc=0
integer totalfc=0
echo
echo '======================='
echo "== CODE LINE COUNTER =="
@rjchatfield
rjchatfield / gitconfig
Created May 16, 2014 07:09
My most used git aliases
[alias]
# Pretty log
lol = log --oneline --graph --pretty='format:%C(auto)%d %s%Creset %>|(60)%C(dim)(%ar) %h%Creset'
# Pretty status
st = status -s
# Add all, then echo the status (of what I just added)
as = !git add --all && git st
@rjchatfield
rjchatfield / SwiftKeybinding.md
Created June 10, 2014 01:03
A simple trick to overcome the most difficult part of Swift "->"

Swift Keybinding

Hate typing -> ? Try this.

  • Use Terminal to open :
subl /Applications/Xcode.app/Contents/Frameworks/IDEKit.framework/Versions/A/Resources/IDETextKeyBindingSet.plist
  • Add this to the bottom of the file.
@rjchatfield
rjchatfield / gist:3b7052077d58f4143170
Created July 21, 2014 11:45
Where are the Enums?
/**
* Functions that:
* return multiple functions, and also
* contain Structs that:
* contain Classes that:
* contain Functions.
*/
func plusOneFunctions () -> (a:(Int) -> Int, b:(Int) -> Int) {
struct MyStruct {
@rjchatfield
rjchatfield / LinkedList.swift
Last active August 29, 2015 14:05
A Linked List in Swift
// LINKED LIST
/**
* NODE
*/
private class Node<T:protocol<Printable, Comparable>>: Printable, Comparable {
/**
* PROPERTIES
*/
var info:T
@rjchatfield
rjchatfield / callbacks.playground
Created September 9, 2014 03:37
Chaining functions, handling successes and fails through returning structs. Note line111 and line134 are compositions.
/**
MARK: All starts here...
*/
func test <T> (isTrue:BooleanType, success: ()->T, fail: ()->T) -> T {
return isTrue ? success() : fail()
}
/**
MARK: - Callback Data Structures
*/
@rjchatfield
rjchatfield / currying.swift
Created September 28, 2014 04:09
An intro to currying functions in Swift
// Currying
func say (hello: String) (to: String) -> String {
return "\(hello), \(to)."
}
// English
let helloWorld = say("Hello")(to: "world") //-- "Hello, world."
// Spanish
let hola = say("Hola") //-- function