Skip to content

Instantly share code, notes, and snippets.

View diegostamigni's full-sized avatar

Diego Stamigni diegostamigni

View GitHub Profile
@diegostamigni
diegostamigni / retry.go
Created November 2, 2022 15:09
Golang generic retry
func Retry[T any](effector func(ctx context.Context) (T, error), retries int, delay time.Duration) func(context.Context) (*T, error) {
return func(ctx context.Context) (*T, error) {
for r := 0; ; r++ {
response, err := effector(ctx)
if err == nil || r >= retries {
// Return when there is no error or the maximum amount
// of retries is reached.
return &response, err
}
@diegostamigni
diegostamigni / MySQL.pool.php
Created May 28, 2013 20:59
MySQL Pool Maste/Slave
class DB {
private static $cfg = array(
'write' =>
array('mysql:dbname=MyDB;host=10.1.2.3'),
'read' =>
array('mysql:dbname=MyDB;host=10.1.2.7',
'mysql:dbname=MyDB;host=10.1.2.8',
'mysql:dbname=MyDB;host=10.1.2.9');
);
public static function getConnection($pool) {
@diegostamigni
diegostamigni / viron_first_look
Created January 22, 2013 18:25
Viron: Hello world!
[osiris@iside] ~ $ ./viron
Hello world, from Viron!
~ $ mount
Viron: added viron@fuse0 - mounted by osiris
~ $ exit
Viron: umounted viron@fuse0
[osiris@iside] ~ $
@diegostamigni
diegostamigni / history.c
Last active December 11, 2015 10:18
history.c || implement a queue --> designed to be used as a command history.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/conf.h>
#include <env/history.h>
#define HISTORY_SIZE 10
#define FIRST_ELEMENT 0
#define LAST_ELEMENT (HISTORY_SIZE - 1)
// private function -- dealloc element in history at position x
@diegostamigni
diegostamigni / memagent.h
Created January 21, 2013 10:59
memagent.h used in Viron.
#ifndef __MEMAGENT_H
#define __MEMAGENT_H
#include <stdarg.h>
#include <stdlib.h>
#include <sys/conf.h>
// safe free with the checks if ptr exist
// before cleaning
static inline void safefree(void *ptr) {
@diegostamigni
diegostamigni / gist:4405660
Created December 29, 2012 09:07
CScope build Mac OSX patch-fix
--- src/constants.h 2012-12-29 09:59:37.000000000 +0100
+++ src/constants.h 2012-12-29 09:59:16.000000000 +0100
@@ -103,7 +103,9 @@
#define INCLUDES 8
#define FIELDS 10
-#if (BSD || V9) && !__NetBSD__ && !__FreeBSD__
+#if (__APPLE__)
+# define TERMINFO 1
+#elif (BSD || V9) && !__NetBSD__ && !__FreeBSD__
@diegostamigni
diegostamigni / Gentoo Rocks
Created December 26, 2012 22:14
Gentoo Linux Rocks.
osiris@Gentoo ~ $ du -sh /boot/kernel-x86_64-3.7.1-gentoo
3.9M /boot/kernel-genkernel-x86_64-3.7.1-gentoo
osiris@Gentoo ~ $ du -sh /lib/modules/3.7.1-gentoo/
260K /lib/modules/3.7.1-gentoo/
osiris@Gentoo ~ $ uname -a
Linux Gentoo 3.7.1-gentoo #1 SMP Mon Dec 24 16:42:53 CET 2012 x86_64 Intel(R) Core(TM) i7-3615QM CPU @ 2.30GHz GenuineIntel GNU/Linux
osiris@Gentoo ~ $