Skip to content

Instantly share code, notes, and snippets.

View danielres's full-sized avatar

Daniel Reszka danielres

View GitHub Profile
@danielres
danielres / signals.ts
Last active October 5, 2023 10:34
A minimal signals implementation in typescript. This is a toy example to help me wrap my head around the pattern.
export type Signal<T> = ReturnType<typeof createSignal<T>>
export function createSignal<Value>(initialValue: Value): {
subscribe: (listener: (v: Value) => void) => () => void
val: Value
} {
let value = initialValue
const listeners: ((v: Value) => void)[] = []
function subscribe(listener: (v: Value) => void) {
@danielres
danielres / Ratio.svelte
Last active September 25, 2023 09:22
Svelte component to fill all available space while maintaining aspect ratio.
<!--
@component
Allows to create responsive containers with a fixed aspect ratio.
Uses container queries to determine the size of the container.
The contained element will be as large as possible while maintaining the aspect ratio.
@example
```tsx
<div class="outer h-[100svh] grid grid-rows-[auto_1fr_auto]">
@danielres
danielres / .eslintignore
Last active June 8, 2020 06:53
nextjs typescript config
node_modules
dist
coverage
.eslintrc.js
@danielres
danielres / apollo-server-express-middlewares-example.js
Last active May 26, 2020 09:05
using express js middlewares in apollo server graphql context
import { ApolloServer, gql } from "apollo-server-micro"
import cookieSession from "cookie-session"
const ONE_HOUR = 60 * 60 * 1000
const typeDefs = gql`
type Query {
hello: String!
}
`
@danielres
danielres / keybase.md
Created January 25, 2020 11:45
keybase.md

Keybase proof

I hereby claim:

  • I am danielres on github.
  • I am danielres (https://keybase.io/danielres) on keybase.
  • I have a public key ASA7WN7ywCsV8R3AKSdH014O0nX8-sWUv4VlO2YxGMWZMwo

To claim this, I am signing this object:

#!/bin/bash
# Finds a process by regexp then terminates
# it, including all subprocesses
# usage: ./terminate <PROCESS_NAME_OR_PATTERN>
kill -TERM -- -$(pgrep -f "$1")
@danielres
danielres / defaultPropsExample.tsx
Last active October 22, 2019 14:11
React + typescript + defaultProps example
// Adapted from: https://github.com/microsoft/TypeScript/issues/27425
// This workaround should become deprecated by: https://github.com/microsoft/TypeScript/pull/29818
import * as React from "react";
Person.defaultProps = { telephone: "222-333-4444" };
function Person({ name, telephone }: { name: string; telephone: string }) {
return (
<div>
@danielres
danielres / curl_wait_for_url.sh
Last active October 11, 2019 12:18
wait for url example
sleep 10
curl --retry 8 --retry-connrefused -v localhost:1234
@danielres
danielres / trapped_lasers_disco.ino
Created November 10, 2017 12:52
trapped lasers disco with distance sensor
#include <Servo.h>
Servo myservo;
// servo & lasers
float pos = 0;
#define LA1 10
#define LA2 11
float minDeg = 80;
fallocate -l 1G /swapfile && \
chmod 600 /swapfile && \
mkswap /swapfile && \
sudo swapon /swapfile && \
swapon --show