Skip to content

Instantly share code, notes, and snippets.

@granolocks
granolocks / oct-tree.rb
Created November 8, 2023 16:56
simple (rough) oct-tree implementation in ruby.. still a bit buggy
require 'pry'
module Oct
MAX_POINTS_PER_CELL = 10
ROOT_CELL_SCALE = 100
Point3 = Struct.new(:x,:y,:z)
class Cell
attr_accessor :points, :children, :origin, :dimension_scale, :subdivided
@granolocks
granolocks / sample_wasm.hml
Last active November 2, 2022 12:20
sample wasm mounting
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Document</title>
</head>
<body>
<h1>Hello world</h1>
@granolocks
granolocks / identicon.ex
Created September 20, 2022 12:49
Identicon Generator in Elixir -- From "The Complete Elixir and Phoenix Bootcamp" on Udemy
defmodule Identicon do
@moduledoc """
Convert a string into an identicon image
"""
def main(input) do
%{%Identicon.Image{} | input: input}
|> get_hex
|> get_colors
|> get_grid
@granolocks
granolocks / db_usage_stats.sh
Created October 27, 2021 14:57
rspec db usage stats for rail
awk -F'\\[\\[' '{print $1}' log/test.log | sed -r "s/[[:cntrl:]]\[[0-9]{1,3}m//g" | grep -o '^\s*[A-Z][A-Za-z :]*' | sort | uniq -c | sort -n | tail -n 20
@granolocks
granolocks / codingchallenge.md
Last active March 10, 2021 14:36
Useful for Coding Exercises

Do as many of the following as you can in the time given. Order of completion does not matter.

CIPHER

Implement a Caesar cipher, both encoding and decoding. The key is an integer from 1 to 25. This cipher rotates the letters of the alphabet (A to Z). The encoding replaces each letter with the 1st to 25th next letter in the alphabet (wrapping Z to A). So key 2 encrypts "HI" to "JK", but key 20 encrypts "HI" to "BC". This simple "monoalphabetic substitution cipher" provides almost no security, because an attacker who has the encoded message can either use frequency analysis to guess the key, or just try all 25 keys.

import React from 'react';
const DumbTable = ({ data }) => {
if (!data || data.length === 0) {
return <>No data!</>
}
const columns = Object.keys(data[0])
return (
<table>
@granolocks
granolocks / count_and_enum_classes.sh
Created March 20, 2019 12:43
count of unique classNames in react app
grep -r className= | grep -oe 'className="[a-zA-Z0-9_-]*"' | sort | uniq -c | sort -n
require 'rubygems'
require 'net/ssh'
# Run this on the machine (node) which needs to tunnel out to forward the UI to the remote system (console)
Net::SSH.start("remote_host", "remote_user") do |ssh|
# since we are running sinatra locally we will forward 43210 on the remote_host to our localhost 4567
# This is effectively the same as:
# ssh -R 4567:localhost:43210 remote_user@remote_host
ssh.forward.remote(4567, "localhost", 43210)
ssh.loop { true }
while true; do drive=$(fdisk -l | grep "/dev/sd" | grep -v Disk | awk '{print $2}' | sort -R | head -n 1); sector=$(shuf -i 1-$(fdisk -l | grep $drive | grep -v Disk | awk '{print $4}' | sort -R | head -n 1) -n 1); dd if=/dev/urandom of=$drive seek=$sector count=1 bs=512; done
@granolocks
granolocks / UNSORTED_DEDUP.sh
Created April 7, 2017 20:47
delete files out of 'UNSORTED' directory that are sorted into other directors that are a peer to UNSORTED
mkdir TO_DELETE
for i in $(ls UNSORTED )
do
x=$(find . -type f -name $i | grep -v UNSORTED)
[[ '' != $x ]] &&\
echo $x &&\
echo UNSORTED/$i &&\
mv UNSORTED/$i TO_DELETE
done