Skip to content

Instantly share code, notes, and snippets.

View droduit's full-sized avatar
🦮
Working on flutter apps

Dominique Roduit droduit

🦮
Working on flutter apps
View GitHub Profile
@droduit
droduit / ripple.css
Last active August 21, 2023 08:44
Material Ripple Effect (touch + mouse)
[ripple] {
position: relative;
.ripple-container {
top: 0; left:0; right: 0; bottom: 0;
position: absolute;
overflow: hidden;
border-radius: inherit;
}
@droduit
droduit / getFilenameFromContentDisposition.ts
Last active March 14, 2023 13:15
Get filename from Content-Disposition header
/**
* Support filename= and filename*= with the priority given to filename*=
* Encoding and locale can optionaly be provided with filename*=
* Return undefined if the content-disposition doesn't contain filename= or filename*=
*/
const { TextDecoder } = require("util");
function getFilenameFromContentDisposition(contentDisposition: string) {
if (!contentDisposition) {
return undefined
@droduit
droduit / fix-serialization.php
Last active May 27, 2021 15:07
Fix serialized data broken due to search & replace in database
<?php
/*
* The `fix_serialized` function fixes serialized data which has been corrupted by an incorrect byte count length,
* especially in the case of a search & replace done on a dump of a wordpress database.
*/
$corruptedSerialization = 'a:3:{i:0;s:150:".DS_Store";i:1;s:100:".git";i:2;s:190:"node_modules";}';
if (is_serialized($corruptedSerialization)) {
$fixed = fix_serialized($corruptedSerialization);
print_r(unserialize($fixed));
}
@droduit
droduit / controller.ts
Last active January 6, 2023 01:24
Add Authorization header with firebase user token to every request made with axios across the application
/*
* Backend implementation: express middleware which checks the firebase user token and execute the request only when the token is verified
*/
import * as express from "express";
import * as admin from "firebase-admin";
import * as functions from "firebase-functions";
admin.initializeApp({
credential: admin.credential.applicationDefault(),
});
@droduit
droduit / api-request-00-how-to-use.js
Last active November 12, 2019 15:30
Simple way to send HTTP requests to an API in JavaScript.
/*
=========================================================
Here is how to use the code
========================================================= */
const jsonApi = api("https://jsonplaceholder.typicode.com/");
// GET, request to "https://jsonplaceholder.typicode.com/todos/1"
jsonApi.get('todos/1', json => console.log(json));
// POST, request to "https://jsonplaceholder.typicode.com/posts"
@droduit
droduit / randomizer-string.js
Last active November 10, 2019 22:12
Generate a fixed-length random string in JavaScript
const randomizer = {
chars : [..."abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNPQRSTUVWXYZ123456789"],
getString : length => [...Array(length)].map(_ => randomizer.chars[Math.random() * randomizer.chars.length|0]).join('')
};
/* How to use
=========================================================
| Code | Example of result |
| randomizer.getString(10) | SeEmxH6haF |
@droduit
droduit / base62.js
Created May 29, 2019 20:16
JS encode / decode base62
// Source : https://lowrey.me/encoding-decoding-base-62-in-es6-javascript/
const base62 = {
charset: '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'.split(''),
encode: integer => {
if (integer === 0) {
return 0;
}
let s = [];
while (integer > 0) {
@droduit
droduit / expiredStorage.js
Last active November 10, 2019 22:16
Cookie-like implementation of localStorage. You can use it as an alternative to cookies.
/**
* Use the browser's local storage to store the data.
* You can optionally give an expiration date in seconds or timestamp.
**/
let cookies = {
get: (key) => {
if (!localStorage.getItem(key) || key === null) {
return null;
}
@droduit
droduit / mysqldump.php
Created November 15, 2018 20:48 — forked from micc83/mysqldump.php
Simple PHP script to dump a MySql database
<?php
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
$database = 'db';
$user = 'user';
$pass = 'pass';
$host = 'localhost';