Skip to content

Instantly share code, notes, and snippets.

View watzon's full-sized avatar
👀
Looking for work

Chris Watson watzon

👀
Looking for work
View GitHub Profile
class CreateOrganizationMembers::V20190614161024 < Avram::Migrator::Migration::V1
def migrate
create :organization_member do
add_belongs_to user : User, on_delete: :cascade
add_belongs_to organization : Organization, on_delete: :cascade
add can_add_shards : Bool
add can_delete_shards : Bool
add can_edit_shards : Bool
add can_edit_info : Bool
@watzon
watzon / decorator_base.cr
Last active June 14, 2019 21:46
Testing decorator implementation with Lucky
abstract class DecoratorBase
private macro decorate(ident, name = nil)
@_{{ ident.id.stringify.downcase.id }} : {{ ident.id }}
forward_missing_to @_{{ ident.id.stringify.downcase.id }}
def initialize(@_{{ ident.id.stringify.downcase.id }} : {{ ident.id }})
end
end
@watzon
watzon / not_pwned_validation.cr
Created June 14, 2019 18:27
Lucky valdator to make sure a password isn't in the Have I Been Pwned database
require "http/client"
require "openssl"
module NotPwnedValidation
def validate_not_in_hibp
password.value.try do |value|
hash = get_sha1_hash(value).upcase
first_five = hash[0...5]
response = HTTP::Client.get("https://api.pwnedpasswords.com/range/" + first_five)
hashes = response.body.split("\r\n")
@watzon
watzon / app.js
Last active June 14, 2019 18:23
Toggle password field with Lucky and stimulus
import { Application } from 'stimulus'
import PasswordController from './controllers/password_controller'
const application = Application.start()
application.register("password", PasswordController)

Keybase proof

I hereby claim:

  • I am watzon on github.
  • I am watzon (https://keybase.io/watzon) on keybase.
  • I have a public key ASAaZc4seSN-ph2udQzAl_qP_oBugNBvq57A5mKu5qQh1go

To claim this, I am signing this object:

# This example will throw an error at compile time
# allowing you to catch it sooner and fix it
arr = [] of Int32
def sum(arr)
arr.reduce(0) { |acc,i| acc + i }
end
# Works just fine
# This example throws a runtime error.
# Yes. This is intentional.
arr = []
def sum(arr)
arr.reduce(0) { |acc,i| acc + i }
end
# Works just fine
# A very basic HTTP server
require "socket"
server = TCPServer.new("localhost", 8080)
puts "Listening on http://localhost:8080"
loop do
socket = server.accept
request = socket.gets
@watzon
watzon / http-server.cr
Last active May 11, 2019 20:24
Doing Crystal #1: A Ruby Comparison
# A very basic HTTP server
require "http/server"
server = HTTP::Server.new do |context|
context.response.content_type = "text/plain"
context.response.print "Hello world, got #{context.request.path}!"
end
puts "Listening on http://127.0.0.1:8080"
server.listen(8080)
@watzon
watzon / media_finder.cr
Created May 11, 2019 11:35
Little script that searches for media using Crystal
class MediaFinder
alias FileInfo = NamedTuple(name: String, directory: String, size: UInt64)
DEFAULT_MEDIA_TYPES = {
images: ["jpg", "jpeg", "gif", "png", "exif", "tiff", "bmp"],
videos: ["webm", "mkv", "flv", "vob", "ogv", "ogg", "gifv", "mng", "avi", "mts", "m2ts", "mov", "qt", "wmv", "mp4", "m4p", "mpg", "mpeg", "m4v", "3gp", "3g2"],
audios: ["aa", "aac", "aax", "aiff", "flac", "m4a", "m4p", "mp3", "ogg", "sln", "wav", "wma"]
}