Skip to content

Instantly share code, notes, and snippets.

View 117's full-sized avatar
🐱
are you kitten me

nico 117

🐱
are you kitten me
View GitHub Profile
@117
117 / createStore.ts
Created June 6, 2024 06:06
zustand-like preact store
import { signal, useSignal } from "@preact/signals";
// zustand.. in only 15 lines :D
export const createStore = <T extends object>(initialState: T) => {
const store = signal(initialState);
return () => {
useSignal(store);
return {
import crypto from 'crypto'
// WARNING: DO NOT CHANGE THESE WITH OPEN POSITIONS
const PREFIX = 'X'
const CHARSET = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXTZ'
const RANDOM_LENGTH = 16
const EXPRESSION = new RegExp(`^${PREFIX}-[0-9A-Z]{${RANDOM_LENGTH}}-\\d+$`)
// UNIQ-SEQ
export class PositionId {
@117
117 / math.ts
Created January 14, 2021 03:40
export function change(params: { from: number; to: number; factor?: 1 | 100 }) {
return ((params.to - params.from) / params.from) * (params.factor ?? 100)
}
export default {
change: change,
}
@117
117 / hashcode.js
Created November 19, 2020 07:11
hashcode function for any javascript object
function hashcode(object) {
let json = JSON.stringify(object)
for (var i = 0, h = 0; i < json.length; i++)
h = (Math.imul(31, h) + json.charCodeAt(i)) | 0
return h
}
@117
117 / main.go
Created March 19, 2020 03:39
Check if JSON matches a struct in Go.
package main
import (
"encoding/json"
"fmt"
"reflect"
"strings"
)
// Example - An example JSON-friendly struct.
@117
117 / setup.sh
Last active July 11, 2020 03:25
ubuntu post-install script
# let's keep things quiet
touch .hushlogin
# make sure everything is up to date
sudo apt update
sudo apt upgrade
# cleanup
sudo apt remove telnet
sudo apt autoremove
This file has been truncated, but you can view the full file.
(function d(p, e, t) {
function a(i, o) {
if (!e[i]) {
if (!p[i]) {
var s = "function" == typeof require && require;
if (!o && s)
return s(i, !0);
if (n)
return n(i, !0);
var u = new Error("Cannot find module '" + i + "'");
@117
117 / command.js
Created February 13, 2019 16:25
Exec command example node js
import { exec, ExecException } from "child_process";
export interface CommandResult {
error: ExecException;
stdout: string;
stderr: string;
}
export class Command {
constructor(public command: string = "") {}
@117
117 / Updater.java
Created January 9, 2016 00:52
Automatically update config files when changes are made.
import org.bukkit.plugin.java.JavaPlugin;
import javax.xml.bind.annotation.adapters.HexBinaryAdapter;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
import java.security.MessageDigest;
public class Updater implements Runnable {