Skip to content

Instantly share code, notes, and snippets.

@ityonemo
ityonemo / test.md
Last active May 1, 2024 15:37
Zig in 30 minutes

A half-hour to learn Zig

This is inspired by https://fasterthanli.me/blog/2020/a-half-hour-to-learn-rust/

Basics

the command zig run my_code.zig will compile and immediately run your Zig program. Each of these cells contains a zig program that you can try to run (some of them contain compile-time errors that you can comment out to play with)

<?
# MIT license, do whatever you want with it
#
# This is my invoice.php page which I use to make invoices that customers want,
# with their address on it and which are easily printable. I love Stripe but
# their invoices and receipts were too wild for my customers on Remote OK
#
require_once(__DIR__.'/../vendor/autoload.php');
@apieceofbart
apieceofbart / test.js
Last active January 18, 2024 17:14
Async testing with jest fake timers and promises
PLEASE CHECK THIS REPO WITH THE EXAMPLES THAT YOU CAN RUN:
https://github.com/apieceofbart/async-testing-with-jest-fake-timers-and-promises
// Let's say you have a function that does some async operation inside setTimeout (think of polling for data)
function runInterval(callback, interval = 1000) {
setInterval(async () => {
const results = await Promise.resolve(42) // this might fetch some data from server
callback(results)
}, interval)
@dmmeteo
dmmeteo / 1.srp.py
Last active April 27, 2024 05:48
SOLID Principles explained in Python with examples.
"""
Single Responsibility Principle
“…You had one job” — Loki to Skurge in Thor: Ragnarok
A class should have only one job.
If a class has more than one responsibility, it becomes coupled.
A change to one responsibility results to modification of the other responsibility.
"""
class Animal:
def __init__(self, name: str):
@Rich-Harris
Rich-Harris / what-is-svelte.md
Last active March 27, 2024 06:09
The truth about Svelte

I've been deceiving you all. I had you believe that Svelte was a UI framework — unlike React and Vue etc, because it shifts work out of the client and into the compiler, but a framework nonetheless.

But that's not exactly accurate. In my defense, I didn't realise it myself until very recently. But with Svelte 3 around the corner, it's time to come clean about what Svelte really is.

Svelte is a language.

Specifically, Svelte is an attempt to answer a question that many people have asked, and a few have answered: what would it look like if we had a language for describing reactive user interfaces?

A few projects that have answered this question:

@getify
getify / 1.js
Last active September 29, 2021 11:58
experiment: mimicking React's new "useState()" hook for stand-alone functions, including "custom hooks"
"use strict";
[foo,bar] = TNG(foo,bar);
// NOTE: intentionally not TNG(..) wrapping useBaz(), so that it's
// basically like a "custom hook" that can be called only from other
// TNG-wrapped functions
function foo(origX,origY) {
var [x,setX] = useState(origX);
var [y,setY] = useState(origY);

How to Think About Monads 2

How to Think about Monads, starts with composition of pure functions and quickly transitioned to composition of pure functions with side-effects. If you haven't read it yet, please do. This continues where that left off.

By the end of that article, we created specialized composition functions that were equivalent to the Monadic bind.

From that article we can conclude that Monadic computations have the following properties:

  1. Functions are executed sequentially
  2. Optionally, control-flow can be short-circuited
@naoki-sawada
naoki-sawada / client.js
Last active May 2, 2024 16:11
Simple socket.io room and auth example
const io = require('socket.io-client');
const socket = io('http://localhost:3000', {
transportOptions: {
polling: {
extraHeaders: {
'Authorization': 'Bearer abc',
},
},
},

Time Travel Debugging

Time Travel refers to the ability to record a tab and later replay it ([WebReplay][wrr]). The technology is useful for local development, where you might want to:

  • pause and step forwards or backwards
  • pause and rewind to a prior state
  • rewind to the time a console message was logged
  • rewind to the time an element had a certain style or layout
  • rewind to the time a network asset loaded

foldr written the normal way and as the dual of unfoldr

The following code was inspired by Kwang's Haskell Blog post titled unfold and fold.

module Main where

import Prelude hiding (foldr)
import Data.Function ((&))