Skip to content

Instantly share code, notes, and snippets.

Avatar
🔎
🔬 🕺 🔒 🌎 👾

Use amazing-print instead gerrywastaken

🔎
🔬 🕺 🔒 🌎 👾
  • Netherlands
View GitHub Profile
View go_gotchas.go
// Interfaces assigned a value of `nil` are not equal to `nil`
package main
import "fmt"
type I interface {
}
type T struct {
@gerrywastaken
gerrywastaken / Exercise: Fibonacci closure.go
Created Oct 26, 2020
Answer to Exercise: Fibonacci closure in A Tour of Go
View Exercise: Fibonacci closure.go
# An answer to https://tour.golang.org/moretypes/26
# This is a bit more readable than other examples that I found online
# Implement a fibonacci function that returns a function (a closure) that returns successive fibonacci numbers (0, 1, 1, 2, 3, 5, ...).
package main
import "fmt"
// fibonacci is a function that returns
// a function that returns an int.
@gerrywastaken
gerrywastaken / debug require loadpath.rb
Created Aug 15, 2020
Find the path that Ruby's require statement tries to load. This is actually inaccurate as it misses steps like checking an absolute path, but it worked for my use case.
View debug require loadpath.rb
def debug_require(path)
$LOAD_PATH.each do |lp|
full_path = "#{lp}/#{path}"
puts full_path if File.file?(full_path)
full_rb_path = "#{full_path}.rb"
puts full_rb_path if File.file?(full_rb_path)
end
end
View test-file-for-logstalgia
proxy-435.dialup.xtra.co.nz - - [22/Apr/2009:18:52:51 +1200] "GET /images/photos/455.jpg HTTP/1.1" 200 986 "-" "Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_4_11; en) AppleWebKit/525.13 (KHTML, like Gecko) Version/3.1 Safari/525.13" "-"
proxy-435.dialup.xtra.co.nz - - [22/Apr/2009:18:52:51 +1200] "GET /images/nav/tab_left_middle.gif HTTP/1.1" 200 1020 "-" "Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_4_11; en) AppleWebKit/525.13 (KHTML, like Gecko) Version/3.1 Safari/525.13" "-"
dyn-530.optus.com.au - - [22/Apr/2009:18:52:51 +1200] "GET /images/photos/5332.jpg HTTP/1.1" 200 244 "-" "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; .NET CLR 1.1.4322)" "-"
dhcp-465.telstra.com.au - - [22/Apr/2009:18:52:51 +1200] "GET /gallery.php?section=entertainment HTTP/1.0" 200 58636 "-" "Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_4_11; en) AppleWebKit/525.13 (KHTML, like Gecko) Version/3.1 Safari/525.13" "-"
proxy-435.dialup.xtra.co.nz - - [22/Apr/2009:18:52:51 +1200] "GET /adclick.php?c=LME2 HTTP/1.1" 302 378 "-" "Moz
View rub_pipes.rb
class Object
def |
yield(self)
end
end
'./public/webpack/manifest.json'
.|(&File.method(:read))
.|(&JSON.method(:parse))
View bleh.js
scriptEl.onload = function() {
alert('yo')
} 
View keybase.md

Keybase proof

I hereby claim:

  • I am gerrywastaken on github.
  • I am gerrywastaken (https://keybase.io/gerrywastaken) on keybase.
  • I have a public key ASAbJrjqql8qJmAmZPeL_3KneKZ9iOh0oWtiQkxWMTKVjgo

To claim this, I am signing this object:

View bigquery-most-popular-gems.sql
View machine_learning_iris_example.rb
iris[0].data = {
target: :setosa
sepal_length: 5.1,
sepal_width: 3.5,
petal_length: 1.4,
petal_width: 0.2
}
@gerrywastaken
gerrywastaken / readonly_example.rb
Created Jun 28, 2012
Make attributes as read only and add errors to the columns
View readonly_example.rb
[:first_name=, :last_name=].each do |current|
alias_attribute current, :read_only
end
protected
def read_only attribute
attribute_name = caller[0][/`([^=']*)='/, 1] # Matches after first ` until = or ' is reached.
error_message = "sorry #{attribute_name} is read-only"
self.errors.add(attribute_name, error_message)
end
You can’t perform that action at this time.