Skip to content

Instantly share code, notes, and snippets.

View chanmix51's full-sized avatar

Grégoire HUBERT chanmix51

View GitHub Profile
@chanmix51
chanmix51 / flat_config.rs
Created April 3, 2023 14:47
FlatConfig example & TODO
use std::{collections::HashMap, error::Error, fmt::Display, path::PathBuf};
#[derive(Debug)]
pub enum ConfigError {
/// Configuration setting named is missing.
Missing(String),
/// Type mismatch
TypeMismatch { expected: String, present: String },
@chanmix51
chanmix51 / diplo.rs
Created February 13, 2023 12:31
ChatGPT generated code for a simple Diplomacy like game
use std::collections::HashMap;
struct Square {
name: String,
pawn: Option<String>,
}
struct GameBoard {
squares: HashMap<String, Square>,
}
@chanmix51
chanmix51 / bashrc
Created December 1, 2019 19:18
bashrc for LXC containers
alias ll='ls -lh'
ylw=$(tput setaf 227)
grn=$(tput setaf 154)
red=$(tput setaf 196);
bld=$(tput bold);
rst=$(tput sgr0);
export PS1="LXC[\[$([ $UID -eq 0 ] && echo "$red" || echo "$grn")\]$(hostname)\[$rst\]]:\[$bld\]\w\[$rst\]# "
parec \
-d alsa_output.pci-0000_00_1f.3.analog-stereo.monitor \
--fix-format --fix-rate --no-remix --file-format=wav \
file.wav
@chanmix51
chanmix51 / arrays_in_bash.md
Last active April 2, 2020 18:26
Using arrays in Bash

Using arrays in bash

creating an array

$> my_array=(one two three)

accessing/setting elements

$> echo ${my_array}

one

@chanmix51
chanmix51 / lauch_baudline
Created July 26, 2017 20:42
baudline on linux mint & pulsaudio
parec --channels=1 --latency-msec=2 | ./baudline -stdin -stdout | pacat
@chanmix51
chanmix51 / phptags.sh
Created June 13, 2017 15:23
Vim exuberent ctags indexing script
#!/bin/bash
ctags-exuberant -f .ctags \
-h '.php' -R \
--exclude='\.git' \
--totals=yes \
--tag-relative=yes \
--PHP-kinds=+cfiv \
--language-force=PHP \
--exclude='*.js' \
--regex-PHP='/(abstract)?\s+class\s+([^ ]+)/\2/c/' \
@chanmix51
chanmix51 / kill_connections.sql
Created May 23, 2017 11:52
kill connections on a specific database
-- gist from http://stackoverflow.com/questions/5108876/kill-a-postgresql-session-connection
-- prevent people from connecting to the database
revoke connect on database :db_name from public, … ;
SELECT
pg_terminate_backend(pid)
FROM
pg_stat_activity
WHERE
-- don't kill my own connection!
pid <> pg_backend_pid()
--
-- PostgreSQL database dump
--
-- Dumped from database version 10.3 (Debian 10.3-1.pgdg70+1)
-- Dumped by pg_dump version 10.3 (Debian 10.3-1.pgdg70+1)
SET statement_timeout = 0;
SET lock_timeout = 0;
SET idle_in_transaction_session_timeout = 0;
@chanmix51
chanmix51 / restart_pgtap.sql
Created July 17, 2015 13:32
Restarting PgTap plan
CREATE OR REPLACE FUNCTION public.restart_plan()
RETURNS void
LANGUAGE sql
AS $function$
truncate table pg_temp_2.__tcache__;
alter sequence pg_temp_2.__tresults___numb_seq restart ;
alter sequence pg_temp_2.__tcache___id_seq restart ;
$function$