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
@watzon
watzon / organization.cr
Last active June 18, 2019 23:05
Lucky Models
class Organization < BaseModel
table :organizations do
column name : String
column email : String
column profile_image_url : String?
column description : String?
column github_username : String?
column gitlab_username : String?
column twitter_username : String?
@watzon
watzon / shard.yml
Created June 17, 2019 06:31
Files for Tourmaline docker container
name: tourmaline-bot
version: 0.1.0
authors:
- Your Mane <[email protected]>
crystal: 0.28.0
dependencies:
tourmaline:
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