Skip to content

Instantly share code, notes, and snippets.

View matschik's full-sized avatar
💚

Mathieu Schimmerling matschik

💚
View GitHub Profile
@matschik
matschik / prefixed_random_id.sql
Last active January 27, 2024 15:37
PostgreSQL function for automatic Object IDs. Inspired by Stripe: https://dev.to/stripe/designing-apis-for-humans-object-ids-3o5a
CREATE OR REPLACE FUNCTION random_string(length INTEGER) RETURNS TEXT AS $$
DECLARE
chars TEXT[] := ARRAY['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9'];
result TEXT := '';
i INTEGER;
BEGIN
FOR i IN 1..length LOOP
result := result || chars[1 + RANDOM() * (array_length(chars, 1) - 1)];
END LOOP;
RETURN result;
@matschik
matschik / decodeUTF8.js
Created July 16, 2019 12:09
Decode UFT8 js
// to avoid using decodeURIComponent(escape(s)) because escape() is not recommended anymore on Ecmascript spec (see MDN).
// more info here about this: http://ecmanaut.blogspot.com/2006/07/encoding-decoding-utf8-in-javascript.html
function decodeUTF8(utftext) {
var string = "";
var i = 0;
var c = (c1 = c2 = 0);
while (i < utftext.length) {
c = utftext.charCodeAt(i);
@matschik
matschik / doc.md
Last active November 20, 2018 12:47
Imba documentation

ES6 Map

var fruits = ['apple', 'orange', 'banana']

var onlyCouscous = 
	fruits.map 
		do |fruit| return 'couscous'

console.log onlyCouscous # ["couscous", "couscous", "couscous"]
@matschik
matschik / reddit-realtime.html
Last active August 30, 2018 17:53
Reddit Realtime JS
<!DOCTYPE html>
<meta name="robots" content="noindex">
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>Reddit Realtime</title>
<link href="https://fonts.googleapis.com/css?family=IBM+Plex+Sans" rel="stylesheet">
<style>