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
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
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

Keybase proof

I hereby claim:

  • I am granolocks on github.
  • I am gkoss (https://keybase.io/gkoss) on keybase.
  • I have a public key ASCu0e73ySuZFwdaD9C5pzgWLculkuysYP0urUE9zShPQgo

To claim this, I am signing this object:

@granolocks
granolocks / colorize strings.md
Last active February 9, 2017 21:50
helpful extension to strin gclass which allows you to magically color strings for putsing

Try something like:

require './colorize_string.rb'
puts [
  "This".red, 
  "is".yellow, 
  "very".underline_cyan, 
  "colorful.".bold_green
 ].join(' ')