Skip to content

Instantly share code, notes, and snippets.

@lukas2
lukas2 / blockdeclsyntax.md
Created Jun 6, 2019 — forked from swizzlr/blockdeclsyntax.md
Block Declaration Syntax List, originally by [pcperini](http://stackoverflow.com/a/9201774/929581), parsed to markdown for printing with your favourite CSS (I recommend @ttscoff's Marked)
View blockdeclsyntax.md

List of Block Declaration Syntaxes

Throughout, let

  • return_type be the type of object/primitive/etc. you'd like to return (commonly void)
  • blockName be the variable name of the block you're creating
  • var_type be the type object/primitive/etc. you'd like to pass as an argument (leave blank for no parameters)
  • varName be the variable name of the given parameter And remember that you can create as many parameters as you'd like.

Blocks as Variables

Possibly the most common for of declaration.

@lukas2
lukas2 / AsynchronousOperation.swift
Created Mar 11, 2019 — forked from calebd/AsynchronousOperation.swift
Concurrent NSOperation in Swift
View AsynchronousOperation.swift
import Foundation
/// An abstract class that makes building simple asynchronous operations easy.
/// Subclasses must implement `execute()` to perform any work and call
/// `finish()` when they are done. All `NSOperation` work will be handled
/// automatically.
open class AsynchronousOperation: Operation {
// MARK: - Properties
View gist:caa72006e6efaa0fb7b823a690bd9f6d
export PAGE="Paul Graham" && clear && curl "https://en.wikiquote.org/w/index.php?title=$(echo $PAGE | sed 's/[[:blank:]]/_/g')&action=edit" 2>/dev/null | grep "\s*\*\s[^\[\*]" | sed 's/^\*[[:blank:]]//g' | sort -R | head -n 1 | fold -s
@lukas2
lukas2 / gist:c198ce090bb9d38bcb53cc2b3e55e65b
Created Jan 25, 2019
gets paul graham quotes on the shell
View gist:c198ce090bb9d38bcb53cc2b3e55e65b
export PAGE="Paul Graham" && clear && curl "https://en.wikiquote.org/w/index.php?title=$(echo $PAGE | sed 's/[[:blank:]]/_/g')&action=edit" 2>/dev/null | grep "\s*\\s[^\[\]" | sed 's/^\*[[:blank:]]//g' | sort -R | head -n 1 | fold -s
View gist:64eafa1d04c2ed057453444cedd70301
# Ways to execute a shell script in Ruby
# Example Script - Joseph Pecoraro
cmd = "echo 'hi'" # Sample string that can be used
# 1. Kernel#` - commonly called backticks - `cmd`
# This is like many other languages, including bash, PHP, and Perl
# Returns the result of the shell command
# Docs: http://ruby-doc.org/core/classes/Kernel.html#M001111
@lukas2
lukas2 / .swift
Created Jan 5, 2018
How to apply CI Filter in Swift
View .swift
// example with CIColorPosterize
let context = CIContext(options: nil)
var ciImage = CIImage(cgImage: image.cgImage!)
ciImage = ciImage.applyingFilter("CIColorPosterize", parameters: ["inputImage" : ciImage, "inputLevels" : 2])
let cgImage = context.createCGImage(ciImage, from: ciImage.extent)!
let filteredUiImage = UIImage(cgImage: cgImage, scale: image.scale, orientation: .up)
View divide by zero
class Fixnum
alias_method :_div, :/
def /(a)
if a == 0
0
else
_div a
end
end
View Marks
# src: http://jeroenjanssens.com/2013/08/16/quickly-navigate-your-filesystem-from-the-command-line.html
export MARKPATH=$HOME/.marks
function jump {
cd -P $MARKPATH/$1 2>/dev/null || echo "No such mark: $1"
}
function mark {
mkdir -p $MARKPATH; ln -s $(pwd) $MARKPATH/$1
}
function unmark {
View gist:4721981

Sublime Text 2 – Useful Shortcuts (Mac OS X)

General

⌘T go to file
⌘⌃P go to project
⌘R go to methods
⌃G go to line
⌘KB toggle side bar
⌘⇧P command prompt
View cryptohelpers (osx)
function decryptc(){
pbpaste > /tmp/encrypted_message.txt; gpg -d /tmp/encrypted_message.txt | pbcopy; rm /tmp/encrypted_message; pbpaste
}
function encryptc(){
pbaste | gpg -e -a -r $1 | pbcopy
}