Skip to content

Instantly share code, notes, and snippets.

View olavoasantos's full-sized avatar

Olavo Amorim Santos olavoasantos

  • Shopify
  • Winnipeg, MB
View GitHub Profile
@barelyhuman
barelyhuman / *Caddyfile.md
Last active February 23, 2025 23:10
Simple http2 server with caddy for static websites

Static File Server

Even though you should generally use a CDN for something like this, a very simple setup for smaller static websites on a VPS / VM is fine.

This gist comes with an example Caddyfile that can be used with caddy to serve any sub-folder in the /var/www path as a subdomain.

This reduces the overall effort required to create and register domains if you are going to keep it all on the same server.

The example Caddyfile shows how to set the flow up with the localhost domain but changing it to work with an actual domain should be rather simple and is documented as comments in the file.

This middleware does a few interesting things:

  • Ensures a url shape in the zustand store, where we'll store URL information.
  • Assumes we will be storing our url state slice in the ?state search parameter after it has been stringified and base 64 encoded.
  • On creation, decodes stores state from the ?state search parameter into the url slice of our store.
  • After each state update, updates the ?state search parameter with the new url state slice.
  • Sets up an event listener that listens for popstate and re-decodes the state from the URL into our store.
@codecitizen
codecitizen / serverless.yml
Created November 22, 2018 20:42
A serverless.yml file configuring a AWS ElastiCache redis instance that is accessible by all AWS Lambda functions deployed by this serverless function.
service: my-service
provider:
name: aws
runtime: nodejs8.10
stage: ${opt:stage, 'dev'}
environment:
REDIS_HOST:
"Fn::GetAtt": [ElasticCacheCluster, RedisEndpoint.Address]
functions:
@eloypnd
eloypnd / dnsmasq_setup_osx.md
Last active October 9, 2024 19:13
wildcard DNS record on OS X in localhost development with dnsmasq

wildcard DNS in localhost development

$ brew install dnsmasq
   ...
$ cp /usr/local/opt/dnsmasq/dnsmasq.conf.example /usr/local/etc/dnsmasq.conf
  • edit /usr/local/etc/dnsmasq.conf
address=/local/127.0.0.1
@banksean
banksean / mersenne-twister.js
Created February 10, 2010 16:24
a Mersenne Twister implementation in javascript. Makes up for Math.random() not letting you specify a seed value.
/*
I've wrapped Makoto Matsumoto and Takuji Nishimura's code in a namespace
so it's better encapsulated. Now you can have multiple random number generators
and they won't stomp all over eachother's state.
If you want to use this as a substitute for Math.random(), use the random()
method like so:
var m = new MersenneTwister();