Skip to content

Instantly share code, notes, and snippets.

View rainforest-of-code's full-sized avatar

rainforest-of-code

View GitHub Profile
@nathansmith
nathansmith / [1] SlotWrapper.svelte
Last active September 8, 2022 14:58
Svelte component, to help test "slot" content
<script lang="ts">
// ======
// Props.
// ======
const { Component, slot, ...otherProps } = $$props;
</script>
<!--
=======
@SimonAlling
SimonAlling / RebindableSyntax.hs
Last active May 23, 2020 16:25
Haskell RebindableSyntax example
{-# LANGUAGE RebindableSyntax #-}
import Prelude hiding ((>>))
data Config = Config { depth :: Int, width :: Int }
printInfo :: Config -> IO ()
printInfo config = mapM_ putStrLn $ do
"************** INFORMATION **************"
"Welcome to the Hydraulic Press Channel."
@mikowl
mikowl / oneliners.js
Last active June 29, 2024 17:39
👑 Awesome one-liners you might find useful while coding.
// Inspired by https://twitter.com/coderitual/status/1112297299307384833 and https://tapajyoti-bose.medium.com/7-killer-one-liners-in-javascript-33db6798f5bf
// Remove any duplicates from an array of primitives.
const unique = [...new Set(arr)]
// Sleep in async functions. Use: await sleep(2000).
const sleep = (ms) => (new Promise(resolve => setTimeout(resolve, ms)));
// or
const sleep = util.promisify(setTimeout);
@munificent
munificent / generate.c
Last active September 15, 2024 03:16
A random dungeon generator that fits on a business card
#include <time.h> // Robert Nystrom
#include <stdio.h> // @munificentbob
#include <stdlib.h> // for Ginny
#define r return // 2008-2019
#define l(a, b, c, d) for (i y=a;y\
<b; y++) for (int x = c; x < d; x++)
typedef int i;const i H=40;const i W
=80;i m[40][80];i g(i x){r rand()%x;
}void cave(i s){i w=g(10)+5;i h=g(6)
+3;i t=g(W-w-2)+1;i u=g(H-h-2)+1;l(u
class Client
attr_reader :key,
def initialize(key)
@key = key
end
end
Client.new("moo") # results in: ArgumentError: wrong number of arguments (given 1, expected 0)
import { useState, useEffect } from 'react';
export interface UseFetchData<TData> {
data: TData;
isLoading: boolean;
error?: string;
}
export const useFetchData = <TData>(fetchUrl: string, defaultValue: TData): UseFetchData<TData> => {
const [data, setData] = useState<TData>(defaultValue);
import { EasingName, easing } from './easingMap';
import { useLayoutEffect, useState, useRef } from 'react';
export interface AnimationIncreaseProps {
easingName?: EasingName;
duration?: number;
diff: number;
}
export const useIncreaseAnimation = ({
@kofigumbs
kofigumbs / elm_converter.rb
Last active March 30, 2019 19:58
Compile Elm files and include the JavaScript output in a Jekyll site
# Initially based on https://github.com/sonnym/jekyll_elm
#
# USAGE:
# Copy/paste this file into the `_plugins` directory of your Jekyll project.
# For every .elm file in your project, it will generate a .js file in your site
# using the same name and relative path.
#
# As-is, the converter expects the following directory structure:
#
# your-jekyll-project/
# vim: set ft=ruby
cask_args appdir: '/Applications'
tap 'homebrew/cask'
brew 'mas'
brew 'git'
brew 'zsh'
brew 'make'
@johnynek
johnynek / TreeList.scala
Created December 14, 2018 19:45
Implementation of "Purely Functional Random Access Lists" by Chris Okasaki in scala. This gives O(1) cons and uncons, and 2 log_2 N lookup.
package org.bykn.list
import cats.Applicative
import cats.implicits._
/**
* Implementation of "Purely Functional Random Access Lists" by Chris Okasaki.
* This gives O(1) cons and uncons, and 2 log_2 N lookup.
*/