Skip to content

Instantly share code, notes, and snippets.

View marcusandre's full-sized avatar

Marcus André marcusandre

View GitHub Profile
@marcusandre
marcusandre / iban-regex.md
Last active December 11, 2018 09:23
IBAN regular expressions

IBAN regular expression

The following regular expression will match:

  • AB12 1234 1234 1234 1234
  • AB12 1234 1234 1234 1234 1
  • AB12 1234 1234 1234 1234 12

but also:

@marcusandre
marcusandre / sw.js
Last active November 19, 2018 09:12
Simple Service Worker to respond with cached request
(function () {
'use strict'
self.addEventListener('fetch', event => {
let request = event.request
if (request.method !== 'GET') {
return
}
event.respondWith(
caches.match(request)
.then(response => {
@marcusandre
marcusandre / mysql.service
Last active October 16, 2018 04:42
get mysql config file hierarchy on the system
/usr/sbin/mysqld --verbose --help | grep -A 1 "Default options"
@marcusandre
marcusandre / vagrant-suspend-all.sh
Created February 15, 2018 10:47
Suspend all running vagrant machines
#!/usr/bin/env bash
ids=$(vagrant global-status | grep 'running' | cut -d ' ' -f 1 | xargs)
vagrant suspend $ids
* {
box-sizing: border-box;
text-rendering: optimizeLegibility;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
font-kerning: auto;
}
html {
font-family: sans-serif;
@marcusandre
marcusandre / key.go
Created January 9, 2018 09:24
Generate a random key with crypto/rand
// Example to generate a random key with crypto/rand.
// It's useful to use it for example to prevent request forgery by comparing it
// inside requests.
package main
import (
"crypto/rand"
"fmt"
"log"
@marcusandre
marcusandre / wp_replace.sql
Created January 2, 2015 16:35
replace wordpress database content when migrating.
update wp_options set option_value = replace(option_value,'http://old_domain.com','http://new_domain.com');
update wp_postmeta set meta_value = replace(meta_value,'http://old_domain.com','http://new_domain.com');
update wp_posts set post_content = replace(post_content,'http://old_domain.com','http://new_domain.com');
update wp_posts set guid = replace(guid,'http://old_domain.com','http://new_domain.com');
update wp_posts set pinged = replace(pinged,'http://old_domain.com','http://new_domain.com');
update wp_comments set comment_content = replace(comment_content,'http://old_domain.com','http://new_domain.com');
@marcusandre
marcusandre / immutable.js
Created November 13, 2017 07:48
Immutable array operations
clone = x => [...x]
push = y => x => [...x, y]
pop = x => x.slice(0, -1)
unshift = y => x => [y, ...x]
shift = x => x.slice(1)
sort = f => x => [...x].sort(f)
del = i => x => [...x.slice(0, 1), ...x.slice(i + 1)]
splice = (s, c, ...y) => x => [...x.slice(0, s), ...y, ...x.slice(s + c)]
@marcusandre
marcusandre / pseudo-blockchain.go
Last active October 12, 2017 21:44
An ordered and back-linked list in Go
package blockchain
import (
"bytes"
"crypto/sha256"
"strconv"
"time"
)
type Blockchain struct {
# Options
setopt emacs
setopt nobeep
setopt nonomatch
setopt shnullcmd
setopt extendedglob
setopt bashautolist
setopt noautomenu
setopt noalwayslastprompt