Skip to content

Instantly share code, notes, and snippets.

View Godefroy's full-sized avatar

Godefroy Godefroy

View GitHub Profile
export function incrementAsync(n) {
return async (dispatch, getState) => {
console.log('initial count', getState().counter.count)
dispatch({ type: 'COUNTER_COUNTING', counting: true })
for (let i = 1; i <= n; i++) {
dispatch({ type: 'COUNTER_INCREMENT', n: 1 })
await new Promise(resolve => setTimeout(resolve, 500))
}
dispatch({ type: 'COUNTER_COUNTING', counting: false })
}
export default prepareStore(initialState, {
// Action "incrementAsync" that increments multiple times
// We're using an async generator to yield multiple partial states
// and execute asynchronous operations
async *incrementAsync(n) {
// We can access the current state with "this"
// We shouldn't need this too often. It's like thunks' getState()
console.log('initial count', this.count)
// Instead of dispatching an action as w're used to with redux-thunk,
const initialState = {
count: 0,
counting: false
}
// Actions
export function reset() {
return { type: 'COUNTER_RESET' }
}
import { prepareStore } from 'redux-zap'
const initialState = {
count: 0,
counting: false
}
export default prepareStore(initialState, {
// Action "reset" that set count to 0
// We return a partial state that will be applied to the current state
@Godefroy
Godefroy / admin.php
Last active November 7, 2020 21:49
TP PHP Procédural - Site basique avec interface admin
<?php
include 'check_auth.php';
$username = $_SESSION['username'];
// Cookie "visits"
if (isset($_COOKIE['visits']) && ctype_digit($_COOKIE['visits'])) {
$visits = $_COOKIE['visits'] + 1;
} else {
$visits = 1;
@Godefroy
Godefroy / .gitignore
Created February 9, 2016 15:45
Unity .gitignore
# =============== #
# Unity generated #
# =============== #
/Temp/
/Library/
# ===================================== #
# Visual Studio / MonoDevelop generated #
# ===================================== #
ExportedObj/
@Godefroy
Godefroy / backup-mysql.sh
Created August 21, 2015 09:19
Instant backup of a MySQL database with LVM snapshot
#! /bin/bash
## Instant backup of a MySQL database with LVM snapshot
## Author: Godefroy de Compreignac (@Godefroy)
## License: Beerware
# Instructions:
# - MySQL Data on DB server must be an logical LVM partition
# - Backup server must have ssh root access to DB server
# - Master status is saved at the exact moment of snapshot to allow restoration of master-slave replication
@Godefroy
Godefroy / troll.php
Created September 24, 2012 18:56
Balanced parentheses? in #PHP
<?php
function isBalanced($str){
$count = 0;
$length = strlen($str);
for($i = 0; $i < $length; $i++){
if($str[$i] == '(')
$count += 1;
else if($str[$i] == ')')
$count -= 1;
@Godefroy
Godefroy / removeaccents.js
Created April 7, 2012 16:03
String prototype function to remove accents
String.prototype.removeAccents = function(){
var t = this,
a = {
'œ' : 'oe',
'Œ' : 'Oe',
'æ' : 'ae',
'Æ' : 'Ae',
'[ÀÁÂÃÄÅĀĂǍẠẢẤẦẨẪẬẮẰẲẴẶǺĄ]' : 'A',
'[àáâãäåāăǎạảấầẩẫậắằẳẵặǻą]' : 'a',
'[ÇĆĈĊČ]' : 'C',