Skip to content

Instantly share code, notes, and snippets.

View adicuco's full-sized avatar

Adi Cucolaș adicuco

View GitHub Profile
@adicuco
adicuco / zustand-selectors.ts
Last active July 16, 2024 09:56
Zustand Automatically Generated Hooks & Get Selectors
import { type StoreApi, useStore } from "zustand";
type WithHookSelectors<S> = S extends { getState: () => infer T }
? S & { use: { [K in keyof T]: () => T[K] } }
: never;
export function createHookSelectors<S extends StoreApi<object>>(_store: S) {
const store = _store as WithHookSelectors<typeof _store>;
store.use = {};
for (const key of Object.keys(store.getState())) {
@adicuco
adicuco / tester.ts
Created September 20, 2023 10:41
remix loader/action wrapper for testing
import type { ActionArgs, LoaderArgs } from "@vercel/remix";
import type { Params } from "@remix-run/react";
type Handler<T> = ((args: LoaderArgs) => T) | ((args: ActionArgs) => T);
type TesterArgs = {
path?: string;
body?: Record<string, string>;
headers?: HeadersInit;
@adicuco
adicuco / ci.yaml
Created September 11, 2023 19:30
CI GitHub Action for linting and type checking
name: ⚙️ CI
on:
push:
branches:
- main
pull_request:
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
% vehicle facts
vehicle(bicycle).
vehicle(car).
vehicle(taxi) :-
vehicle(car).
vehicle(bus).
distinct(bicycle, taxi).
distinct(bicycle, car).
distinct(bicycle, bus).
@adicuco
adicuco / huffman.hs
Created January 22, 2020 16:34
Huffman encoding in Haskell
module Main where
import System.IO
import Data.List
import Data.List.Utils
data Tree a = Leaf a | Node a (Tree a) (Tree a) deriving Show
getLeft :: Tree a -> Tree a
getLeft (Node _ x _) = x
@adicuco
adicuco / huffman.js
Created November 8, 2019 18:46
JavaScript Huffman Encoding algorithm
const getFrequency = text => {
let freqs = [];
for (let i = 0; i < text.length; i++) {
const letter = text[i];
const letterIndex = freqs.findIndex(l => l.symbol === letter);
if (letterIndex > -1) {
freqs[letterIndex].weight++;
} else {
const constats = {
MIN_DISTANCE: 2,
MIN_VELOCITY: 3,
MAX_VELOCITY: 2,
MIN_TRAVEL_TIME: 2,
MAX_TRAVEL_TIME: 4
};
const followTarget = () => {
let vector = {
@adicuco
adicuco / bruteZip.py
Created October 16, 2018 09:07
Brute Force zip file (deprecated)
from zipfile import ZipFile
import itertools
charset = "0123456789"
minSize = 1
maxSize = 3
zipName = 'text.zip'
def genPassword():
<?php
$user_id = get_current_user_id();
$codes = array();
global $wpdb;
$querystr = "SELECT * FROM wp_wcg_codes";
$wcg_codes = $wpdb->get_results( $querystr, ARRAY_A);
foreach($wcg_codes as $row){
function createBooking(agent) {
let guests = agent.parameters.guests;
let time = new Date(agent.parameters.time);
let date = new Date(agent.parameters.date);
let bookingDate = new Date(date);
bookingDate.setHours(time.getHours());
bookingDate.setMinutes(time.getMinutes());
let now = new Date();
if (guests < 1){