Skip to content

Instantly share code, notes, and snippets.

View FOLLGAD's full-sized avatar
🌍
meandering

Emil Ahlbäck FOLLGAD

🌍
meandering
View GitHub Profile
### Keybase proof
I hereby claim:
* I am follgad on github.
* I am emilahlback (https://keybase.io/emilahlback) on keybase.
* I have a public key ASBxx4TSjZozItRhSyOD_ceH8PGPmQOG2g7GDDEUg8qVkgo
To claim this, I am signing this object:
@FOLLGAD
FOLLGAD / getHash.js
Created March 3, 2018 16:50
Node.js thesubdb.com hash implementation
const fs = require('fs'),
crypto = require('crypto')
function getHash(pathToFile) {
let readSize = 64 * 1024 // 64kb
return new Promise((resolve, reject) => {
let fd = fs.openSync(pathToFile, 'r')
let buffer = new Buffer(readSize * 2)

Keybase proof

I hereby claim:

  • I am follgad on github.
  • I am emilahlback (https://keybase.io/emilahlback) on keybase.
  • I have a public key ASDC9Qg9zzarwY7QWmaAohK6AI4IC_hOBdyk_cKM9BgtPAo

To claim this, I am signing this object:

@FOLLGAD
FOLLGAD / convert-png.js
Last active January 21, 2021 18:39
Use node to make a png into an array of 1s and 0s (black and white)
let fs = require('fs'),
PNG = require('pngjs').PNG;
fs.createReadStream('./dino_design20by20.png')
.pipe(new PNG({
filterType: 4
}))
.on('parsed', function () {
let arr = []
for (let y = 0; y < this.height; y++) {
@FOLLGAD
FOLLGAD / wakatime-parser.ts
Last active January 21, 2021 18:41
Wakatime data compiler
// This is written for Deno, not node.js
import { readJson } from "https://deno.land/std@0.63.0/fs/read_json.ts"
/*
A script I wrote to parse the data you can download from WakaTime, to display how many hours you spent working on specific
projects.
*/
interface Duration {
@FOLLGAD
FOLLGAD / planetmcScraper.js
Last active May 10, 2021 06:33
Scrape planetminecraft total player count to get an overview of when most people are active to time server updates
// get the stat count from planetminecraft.com
const cheerio = require("cheerio")
const fetch = require("node-fetch")
const fs = require("fs")
const getTheStat = () => {
fetch("https://www.planetminecraft.com/resources/servers/")
.then(res => res.text())
.then(html => {
let planet = cheerio.load(html),
@FOLLGAD
FOLLGAD / setup.sh
Last active December 9, 2021 15:12
sudo apt update && sudo apt upgrade
sudo apt -y install mpv
sudo apt -y install git
sudo apt -y install syncthing
sudo apt -y install transmission-daemon
sudo apt -y install firefox
sudo add-apt-repository ppa:neovim-ppa/unstable
sudo apt -y install neovim
sudo apt -y install fd-find
@FOLLGAD
FOLLGAD / my-age.js
Created March 28, 2022 14:16
gives my age in horrifying detail
const diffInYears = (older, recent) =>
(recent.getTime() - older.getTime())
/ 1000 / 60 / 60 / 24 / 365.25
const myAge = diffInYears(new Date("1999-08-17T04:21:05+02:00"), new Date())
@FOLLGAD
FOLLGAD / rich-editor-with-file-upload.tsx
Last active April 10, 2022 14:54
Upload a file on drop using Outline's "rich-markdown-editor"
import React, { FC } from "react";
import Editor from "rich-markdown-editor";
const uploadFile = async (file: File): Promise<string> => {
// Upload file here, returning the new URL to the file
};
export const RichEditorWithFileUpload: FC = () => {
return (
<Editor
@FOLLGAD
FOLLGAD / hamming.js
Last active May 15, 2022 10:35
Bitburner hamming code solver
// translates dynamic-length hamming codes into raw data
function hamming(n) {
const s = n.length
let o = ""
let errors = []
for (let i = 1; i < s; i++) {
const pw2 = !( i & (i - 1) ) // is power of two
if (!pw2) {
o += n[i]
} else {