Skip to content

Instantly share code, notes, and snippets.

View kuczmama's full-sized avatar
🔥
Building Cool Stuff

Mark Kuczmarski kuczmama

🔥
Building Cool Stuff
View GitHub Profile
@kuczmama
kuczmama / bencode.js
Last active July 24, 2020 12:28
A zero dependency bencode encoder and decoder in javascript
const encode = (data) => {
if(data == null) return null;
if(typeof data === 'number') {
return `i${data}e`;
}
if(typeof data === 'string') {
return `${data.length}:${data}`;
}
@kuczmama
kuczmama / snow-consensus.js
Last active December 24, 2021 20:40
Avalanche Snow consensus in javascript
class Validator {
constructor(id, preference) {
this.id = id;
this.preference = preference;
this.decided = false;
}
}
const describeValidators = (validators) => {
const preferences = {};
@kuczmama
kuczmama / id_to_uuid.rake
Last active July 24, 2022 22:06
Migrate a rails project to use uuids
# Inspired by http://www.madebyloren.com/posts/migrating-to-uuids-as-primary-keys
task id_to_uuid: :environment do
puts "[START] Convert id to uuid"
ActiveRecord::Base.connection.enable_extension 'uuid-ossp' unless ActiveRecord::Base.connection.extensions.include? 'uuid-ossp'
ActiveRecord::Base.connection.enable_extension 'pgcrypto' unless ActiveRecord::Base.connection.extensions.include? 'pgcrypto'
table_names = ActiveRecord::Base.connection.tables - ["schema_migrations", "ar_internal_metadata", "migration_validators"]
table_names.each do |table_name|
puts "[CREATE] uuid column for #{table_name}"