Skip to content

Instantly share code, notes, and snippets.

View C-Duv's full-sized avatar

Duvergier Claude C-Duv

View GitHub Profile
@C-Duv
C-Duv / 1. How to handle, the unique references,codes,ids in both source code and storage?.md
Last active August 29, 2015 14:06
How to handle, the unique references/codes/ids in both source code and storage (eg. database, flat file, etc.)?

TL;DR: Say you have, in a website application, a permission system (user can/cannot access specific section). You need a "name" for this permission/right (eg. can_access_admin) which will somehow be used by storage system (to keep track the fact a user has this right) and into source code (to ask fetch into storage to see if user has the right to access admin area). What form this right "name" has? bits? string? How to use it efficiently in source code: as it (copy/paste)? constant?

When designing a website application you oftenly use concepts such as user permission (eg. access to admin area is granted) and preference (eg. maximum number of results to display in projects list) that will be used among all application.

It boils down to a reference/ID in the form of a string (eg. can_access_admin), bit sequence (eg. 10111) or even integer (42) to use in your source code:

  • Where you fetch value/presence from storage
@C-Duv
C-Duv / foreach_is_modifying_array_cursor_from_outside.php
Created July 21, 2015 10:39
PHP snippet to highlight an array cursor being modified from outside an object or a class
<?php
/**
* Snippet to highlight an array cursor being modified from outside an object or
* a class
**/
class MyClass
{
protected $arr = [];
@C-Duv
C-Duv / blend_web_mix_2015-create_ics.pl
Last active October 24, 2015 19:35
Planning ICS du Blend Web Mix 2015
#!/usr/bin/perl
#
# Script to create an ICS version of the Blend Web Mix 2015 program (http://www.blendwebmix.com/programme.html)
#
# Parses the program web page, every conference web pages and creates an ICS
#
# @author DUVERGIER Claude (http://blog.claude.duvergier.fr)
use 5.010;
@C-Duv
C-Duv / IndexController.php
Created January 3, 2013 02:28
Reproduction code for ZF-12494 (http://framework.zend.com/issues/browse/ZF-12494): A class implementing __wakeup() and a controller using it.
<?php
class IndexController extends Zend_Controller_Action
{
public function indexAction()
{
switch ($this->_getParam('what', 'test')) {
case 'store': $this->_store(); break;
case 'retrieve': $this->_retrieve(); break;
case 'clear': $this->_clear(); break;
--- Zend Framework 1.12.1/library/Zend/Session/Exception.php Thu Jan 05 21:35:02 2012
+++ Zend Framework - Fixed/library/Zend/Session/Exception.php Thu Jan 03 03:17:37 2013
@@ -55,7 +55,9 @@
*/
static public function handleSessionStartError($errno, $errstr, $errfile, $errline, $errcontext)
{
- self::$sessionStartError = $errfile . '(Line:' . $errline . '): Error #' . $errno . ' ' . $errstr;
+ if (error_reporting() !== 0) {
+ self::$sessionStartError = $errfile . '(Line:' . $errline . '): Error #' . $errno . ' ' . $errstr;
+ }
@C-Duv
C-Duv / LibreofficeCalc-KiB-to-UpperBinaryPrefixes
Created December 13, 2013 12:18
Pour LibreOffice Calc : Convertir des Kio en Kio, Mio, Gio, Tio tout en affichant l'unité. Notes : * Dans l'exemple, les Kio sont contenu dans la cellule A1 * Un arrondi est effectué (peut être retiré sans impact autre que visuel)
=SI(
A1/1024>=1;
SI(
A1/1024/1024>=1;
SI(
A1/1024/1024/1024>=1;
CONCATENER(ARRONDI(A1/1024/1024/1024;3);" Tio");
CONCATENER(ARRONDI(A1/1024/1024;3);" Gio")
);
CONCATENER(ARRONDI(A1/1024;3);" Mio")
@C-Duv
C-Duv / script_device_MPD_Radio.lua
Last active December 9, 2017 12:54
A LUA script for Domoticz that controls an MPD server volume (via `mpc` client) under the orders of a dummy Domoticz dimmer
--
-- LUA script for Domoticz that controls an MPD server (via `mpc` client) under
-- the orders of a dummy Domoticz dimmer device.
--
-- No configuration required on the device, the LUA script listen to order such
-- as "Set Level: 42 %" and sends adequate `mpc volume` commands.
--
commandArray = {}
-- Name of the dummy Domoticz dimmer:
@C-Duv
C-Duv / mongoose-gh7608-pass_data_from_debug_to_post_hook.js
Created March 14, 2019 17:05
Mongoose - GH7608: Pass data from debug to post hook
const { MongoMemoryServer } = require('mongodb-memory-server');
const mongoose = require('mongoose');
const mongoServer = new MongoMemoryServer({
'instance': {
'dbName': 'temp',
'port': 35555,
}
});
@C-Duv
C-Duv / mongoose-debug_pre_post_hooks_order-reproduction-code.js
Last active April 8, 2019 09:55
Mongoose debug, pre, post hooks order
const { MongoMemoryServer } = require('mongodb-memory-server');
const mongoose = require('mongoose');
const mongoServer = new MongoMemoryServer({
'instance': {
'dbName': 'temp',
'port': 35555,
}
});
@C-Duv
C-Duv / README.md
Last active December 19, 2019 12:07
Mongoose - Trying to determine collection and operation inside hook for insert/update/delete queries

This gist is to help me find a way to determine the updated collection and the operation (document insertion, update or removal) from inside a Mongoose hook.

How to run

  1. git clone this gist
  2. Run npm install
  3. Execute with node app.js