Skip to content

Instantly share code, notes, and snippets.

Avatar
🔥
Building Cool Stuff

Mark Kuczmarski kuczmama

🔥
Building Cool Stuff
View GitHub Profile
@kuczmama
kuczmama / bencode.js
Last active Jul 24, 2020
A zero dependency bencode encoder and decoder in javascript
View bencode.js
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 / async-callbacks.js
Created Jun 14, 2020
Async Callbacks in javascript
View async-callbacks.js
function fetchSports(prefix, callback) {
console.log("prefix", prefix);
const sports = ["vikings", "vipers"];
setTimeout(() => callback(sports), 500);
}
function fetchNews(prefix, callback) {
const news = ["victory", "votes"];
setTimeout(() => {
callback(news);
@kuczmama
kuczmama / decision_tree.rb
Last active Mar 5, 2020
A decision tree written in ruby
View decision_tree.rb
#!/usr/bin/env ruby
# frozen_string_literal: true
require 'set'
require 'pry'
require 'csv'
require 'optparse'
require 'time'
View fashion-mnist.py
# https://deeplizard.com/learn/video/0VCOG8IeVf8
import torch
import torch.nn as nn
import torch.nn.functional as F
import os.path
# Optimizer to update the weights
import torch.optim as optim
import torchvision
View websocket-reconnect.js
function connect() {
const URL = 'wss://localhost:8080';
const RECONNECT_DELAY = 1000;
const WAIT_FOR_NO_MESSAGE = 30000;
const handler = null;
var ws = new WebSocket(URL);
ws.onmessage = function(e) {
clearTimeout(handler);
setTimeout(() => ws.close(), WAIT_FOR_NO_MESSAGE);
@kuczmama
kuczmama / increase-swap.sh
Created Oct 3, 2019
Increase swap space in ubuntu 18.04
View increase-swap.sh
sudo fallocate -l 16G /swapfile
sudo chmod 600 /swapfile
sudo mkswap /swapfile
echo '/swapfile none swap sw 0 0' | sudo tee -a /etc/fstab
sudo mount -a
swapon -s
@kuczmama
kuczmama / schema.sh
Created May 21, 2019
Heroku to RDS migration script from single to multi-tenant
View schema.sh
#/bin/sh
usage() { echo "Usage: $0 APP_NAME DESTINATION SCHEMA_NAME" 1>&2; exit 1; }
if [ "$#" -ne 3 ]; then
usage
fi
function pathParts() {
url=$1
@kuczmama
kuczmama / markov_chain.rb
Last active May 16, 2019
n level markov chain to randomly generate text
View markov_chain.rb
class String
def blank?
self.nil? || self.empty?
end
def present?
!self.blank?
end
end
@kuczmama
kuczmama / id_to_uuid.rake
Last active Nov 6, 2019
Migrate a rails project to use uuids
View id_to_uuid.rake
# 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}"
@kuczmama
kuczmama / ubuntu-bootstrap.sh
Last active Oct 15, 2018
Install script to setup ubuntu 18.04
View ubuntu-bootstrap.sh
#/bin/bash
usage() { echo "The usage is"; }
while getopts ':h:u:p:r:' opt; do
case "${opt}" in
h) HOST=${OPTARG};;
u) UNAME=${OPTARG};;
p) PWORD=${OPTARG};;
r) RUBY_VERSION=${OPTARG};;
You can’t perform that action at this time.