Skip to content

Instantly share code, notes, and snippets.

View daformat's full-sized avatar

Mathieu Jouhet daformat

View GitHub Profile
@daformat
daformat / utf-spaces-test.js
Last active March 6, 2018 04:01
Testing which utf spaces matches against which regular expression
// Spaces information was found on http://jkorpela.fi/chars/spaces.html
// and https://en.wikipedia.org/wiki/Tab_key#Unicode
{
// Display booleans or ✅ ❌ emojis
const useEmojiForBooleans = true;
// Spaces are to be tested against the following regular expressions
const testRegexps = [
/\s/, // White-space charcater class
@daformat
daformat / utf-spaces.js
Last active October 25, 2023 08:19
A list of the different UTF spaces
utfSpaces = [
{
name: 'Space',
utf: '\u0020',
html: [' ', ' '],
breaking: true,
width: 'Typically 1/4 em',
unicode_category: 'Separator, Space',
matched_by_s_character_class: true
},
@daformat
daformat / ga-realtime-visitorcount-beeper.js
Last active June 9, 2017 10:31
Beep according to the realtime visitor count on Google Analytics
/*
This is more a simple and naive proof of concept than anything
it's based on [this answer](https://stackoverflow.com/a/41077092/1358317)
on stackoverflow.
*/
(function() {
// Create the audio context
var audioCtx = new(window.AudioContext || window.webkitAudioContext)();
@daformat
daformat / basic-transliterate.js
Last active February 14, 2017 18:12
A basic transliteration function
/* Basic transliteration helper */
function transliterate(str) {
return str.replace(/[ÀÁÂÃÄÅ]/g, 'A')
.replace(/[Æ]/g, 'AE')
.replace(/[Ç]/g, 'C')
.replace(/[ÈÉÊË]/g, 'E')
.replace(/[ÌÍÎÏ]/g, 'I')
.replace(/[Ñ]/g, 'N')
.replace(/[ÒÓÔÕÖ]/g, 'O')
.replace(/[Œ]/g, 'OE')
@daformat
daformat / extract-LegifranceToc-Json.js
Last active January 10, 2017 04:09
[data.gouv.fr] - Extract JSON formatted table of content for any given french legal code (Légifrance's Codes en vigueur)
// Extract JSON table of content from any given french Legal code
// ==============================================================
// author: @daformat <mat.jouhet[at][google's mail service].com>
// lastmod: 2017/01/10
//
// Usage:
// ------
// Execute in javascript console while browsing the toc you're interested in
// see comments if you need to tweak anything.
//
@daformat
daformat / extract-urls.sh
Last active January 3, 2017 10:54
Extract any url found in input URL (the shell-noob way)
#!/bin/zsh
echo "Url to extract values from:";
read TMPCURLURL;
RESULT=`curl -L $TMPCURLURL`;
# Extract urls within double quotes
echo $RESULT | grep -oE "\"http://.*\"" | cut -d " " -f1 | cut -d '"' -f2;
# Extract urls within single quotes
echo $RESULT | grep -oE "'http://.*'" | cut -d " " -f1 | cut -d "'" -f2
@daformat
daformat / wikipedia-extract-img2md.js
Last active August 29, 2015 14:01
Extract images from current wikipedia page to markdown.
(function(){
var $t = $('.thumbcaption'),
$i =$('.image img'),
r="", md, i;
for(i=0; i < $t.length; i++){
r+=("![" + $($t[i]).text().replace(/(\r\n|\n|\r)/gm,"")+"]("+$($i[i]).attr('src').replace(/(\/thumb\/)/gm, "/").replace(/\.(png|svg|jpg|jpeg|bmp|gif)\/.*$/gm, ".$1")+")\n" )
}
md = r+'\nImages from ["'+$('#firstHeading').text()+'" on wikipedia]'+'('+document.location.href+')\n';