This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Validator { | |
constructor(id, preference) { | |
this.id = id; | |
this.preference = preference; | |
this.decided = false; | |
} | |
} | |
const describeValidators = (validators) => { | |
const preferences = {}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const encode = (data) => { | |
if(data == null) return null; | |
if(typeof data === 'number') { | |
return `i${data}e`; | |
} | |
if(typeof data === 'string') { | |
return `${data.length}:${data}`; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
# frozen_string_literal: true | |
require 'set' | |
require 'pry' | |
require 'csv' | |
require 'optparse' | |
require 'time' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#/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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class String | |
def blank? | |
self.nil? || self.empty? | |
end | |
def present? | |
!self.blank? | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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}" |
NewerOlder