Skip to content

Instantly share code, notes, and snippets.

@tdshipley
tdshipley / isJPEG Snippet.go
Last active August 29, 2015 14:23
Finding a jpeg in an array of bytes
func isJPEG(fileBlock []byte) (result bool) {
result = false
if (fileBlock[0] == 0xff && fileBlock[1] == 0xd8 && fileBlock[2] == 0xff && (fileBlock[3] == 0xe0 || fileBlock[3] == 0x0e1)) {
result = true
}
return result
}
@tdshipley
tdshipley / isJPEGBody.go
Last active August 29, 2015 14:24
isJPEG function body
result = false
if (fileBlock[0] == 0xff && fileBlock[1] == 0xd8 && fileBlock[2] == 0xff && (fileBlock[3] == 0xe0 || fileBlock[3] == 0x0e1)) {
result = true
}
return result
@tdshipley
tdshipley / isJPEGIfStatement.go
Last active August 29, 2015 14:24
isJPEG if statement
if (fileBlock[0] == 0xff && fileBlock[1] == 0xd8 && fileBlock[2] == 0xff && (fileBlock[3] == 0xe0 || fileBlock[3] == 0x0e1)) {
result = true
}
@tdshipley
tdshipley / deferInGo.go
Last active August 29, 2015 14:24
Defer in Go example
// Taken from https://golang.org/doc/effective_go.html#defer
func Contents(filename string) (string, error) {
f, err := os.Open(filename)
if err != nil {
return "", err
}
defer f.Close() // f.Close will run when we're finished.
var result []byte
@tdshipley
tdshipley / goIfParenthesis.go
Last active August 29, 2015 14:24
If Statement in Go without extra Parenthesis
if fileBlock[0] == 0xff && fileBlock[1] == 0xd8 && fileBlock[2] == 0xff && (fileBlock[3] == 0xe0 || fileBlock[3] == 0x0e1) {
result = true
}
@tdshipley
tdshipley / addition_example_1.rb
Last active August 29, 2015 14:24
Ruby Addition Example 1
x = 4 + 1
@tdshipley
tdshipley / addition_example_2.rb
Last active August 29, 2015 14:24
Ruby Addition Example 2
x = 4+(1)
@tdshipley
tdshipley / poetry_mode_example_1.rb
Last active August 29, 2015 14:24
Poetry Mode Example 1
out_file.close unless out_file.nil?
@tdshipley
tdshipley / poetry_mode_example_2.rb
Last active August 29, 2015 14:24
Poetry Mode Example 2
out_file.close() unless out_file.nil?()
@tdshipley
tdshipley / poerty_mode_example_3.rb
Last active August 29, 2015 14:24
Poetry Mode Example 3
def method(regular_variable, hash_variable={})
# Internal workings of the method which expects
# one variable and some optional named ones
end
method "12", a: "14"
method "13", b: "15"
method "13", b: "15", a: "14"
method "13", b: "15", a: "14"
method "13", { b: "15", a: "14" }