Skip to content

Instantly share code, notes, and snippets.

@robinpokorny
robinpokorny / parseUuid7Date.js
Created May 8, 2023 12:30
Validate UUIDv7 and parse the timestamp
const uuid7Re = /^[0-9a-f]{8}-[0-9a-f]{4}-7[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;
const parseUuid7Date = (uuid) => {
if (typeof uuid !== `string` || !uuid7Re.test(uuid)) {
throw new TypeError(`Expected UUIDv7. Received: ${String(uuid)} (${typeof uuid})`)
}
const timestampHex = uuid.slice(0, 13).replace(`-`, ``)
const timestamp = Number.parseInt(timestampHex, 16)
return new Date(timestamp)
@jaceklaskowski
jaceklaskowski / Rough Notes about CQRS and ES.md
Last active June 13, 2024 02:32
Rough Notes about CQRS and ES

Rough Notes about CQRS and ES

Once upon a time…

I once took notes (almost sentence by sentence with not much editing) about the architectural design concepts - Command and Query Responsibility Segregation (CQRS) and Event Sourcing (ES) - from a presentation of Greg Young and published it as a gist (with the times when a given sentence was heard).

I then found other summaries of the talk and the gist has since been growing up. See the revisions to know the changes and where they came from (aka the sources).

It seems inevitable to throw Domain Driven Design (DDD) in to the mix.

@KdotJPG
KdotJPG / OpenSimplex2S.java
Last active June 15, 2024 22:49
Visually isotropic coherent noise algorithm based on alternate constructions of the A* lattice.
/**
* K.jpg's OpenSimplex 2, smooth variant ("SuperSimplex")
*
* More language ports, as well as legacy 2014 OpenSimplex, can be found here:
* https://github.com/KdotJPG/OpenSimplex2
*/
public class OpenSimplex2S {
private static final long PRIME_X = 0x5205402B9270C86FL;
@vnorby
vnorby / gist:4116565
Created November 20, 2012 07:25
Bookmarklet to show Paul Graham's essay footnotes inline on hover
javascript:(function(e,t,n,r,i,s,o,u){if(!(i=e.jQuery)||n>i.fn.jquery||r(i)){s=t.createElement("script");s.type="text/javascript";s.src="http://ajax.googleapis.com/ajax/libs/jquery/"+n+"/jquery.min.js";s.onload=s.onreadystatechange=function(){if(!o&&(!(u=this.readyState)||u=="loaded"||u=="complete")){r((i=e.jQuery).noConflict(1),o=1);i(s).remove()}};t.documentElement.childNodes[0].appendChild(s)}})(window,document,"1.8.3",function(e,t){var n=e("font[color]").filter(function(){if(parseInt(e(this).text(),10)>0){return true}return false}).parent();var r=e("body").html();n.each(function(){var t=e(this).attr("href").replace("#","");var n=parseInt(t.replace("f",""),10);var i=new RegExp('<a name="'+t+'">([^]*?)[[]');var s=r.match(i);if(s&&s[0]){var o=e(s[0].replace("<br>","\n")).text().replace(n+"]","");o=o.replace("csell_env = 'mud';","").replace("// Begin Y! Store Generated Code","");var u=e('<div class="note" style="background:#FFFFFF;border:3px solid #000;left:0px;top:15px;width:300px;position:absolute;padding:1
@garth
garth / gist:1388969
Created November 23, 2011 15:29
Convert url image ref into inline base 64 in css with nodejs
var css = 'insert lots of css here';
var files = {};
css = css.replace(/url\((\S*)\.(png|jpg|jpeg|gif)\)/g, function(match, file, type)
{
var fileName = file + '.' + type;
var size = fs.statSync(fileName).size;
if (size > 4096) {
console.log('Skipping ' + fileName + ' (' + (Math.round(size/1024*100)/100) + 'k)');
return match;