Skip to content

Instantly share code, notes, and snippets.

View inoas's full-sized avatar
Working from home


Working from home
View GitHub Profile
inoas /
Created October 31, 2022 23:54 — forked from jimmychu0807/
Conversion between String, str, Vec<u8>, Vec<char> in Rust
use std::str;
fn main() {
// -- FROM: vec of chars --
let src1: Vec<char> = vec!['j','{','"','i','m','m','y','"','}'];
// to String
let string1: String = src1.iter().collect::<String>();
// to str
let str1: &str = &src1.iter().collect::<String>();
// to vec of byte


const shade = 100;
type Shade = 100;


def join_game(user_id, game_id) do
with {:ok, user} <- Users.get(user_id),
{:ok, game} <- Games.get(game_id),
false <- Game.is_full?(game),
false <- Game.is_started?(game),
true <- User.has_permission?(user, game)
Game.add_user(game, user)
# Don't care what specific thing failed
inoas / postgresql_serializable_isolation.sql
Created July 15, 2022 14:11 — forked from nathanl/postgresql_serializable_isolation.sql
PostgreSQL Serializable Isolation - false positives
-- (This code was run in PostgreSQL 9.6.1)
-- Demonstration of how serializable isolation for PostgreSQL, which detects possible
-- interference between concurrent transactions, can produce false positives
-- in psql, create the following table
inoas / cif_validation.php
Created May 12, 2022 08:53 — forked from alphp/cif_validation.php
Spanish CIF validation (PHP)
function cif_validation ($cif) {
$cif = strtoupper($cif);
if (preg_match('~(^[XYZ\d]\d{7})([TRWAGMYFPDXBNJZSQVHLCKE]$)~', $cif, $parts)) {
$nie = array('X', 'Y', 'Z');
$parts[1] = str_replace(array_values($nie), array_keys($nie), $parts[1]);
$cheksum = substr($control, $parts[1] % 23, 1);
return ($parts[2] == $cheksum);
} elseif (preg_match('~(^[ABCDEFGHIJKLMUV])(\d{7})(\d$)~', $cif, $parts)) {
inoas /
Created April 5, 2022 11:16 — forked from maxwelleite/
Script to install Microsoft Vista TrueType Fonts (TTF) aka Microsoft’s ClearType fonts on Ubuntu distros
# Author: Maxwel Leite
# Website:
# Description: Script to install Microsoft Vista TrueType Fonts (TTF) aka Microsoft’s ClearType fonts on Ubuntu distros
# Microsoft added a group of new "ClearType Fonts" to Windows with Windows Vista and Office 2007.
# These fonts are named Constantia, Corbel, Calibri, Cambria (and Cambria Math), Candara, and Consolas.
# Calibri became the default font on Microsoft Word 2007, and it’s still the default font on Word 2016 today.
# Dependencies: wget, fontforge and cabextract
# Note: Microsoft no longer provides the PowerPoint Viewer 2007 (v12.0.4518.1014) or any version anymore for download
# Tested: Ubuntu Saucy/Trusty/Xenial/Bionic

Phoenix 1.4.x to 1.5.0 upgrade instructions

Phoenix 1.5 requires Elixir >= 1.7. Be sure your existing version is up to date by running elixir -v on the command line.

Install the new project generator

$ mix archive.uninstall phx_new
$ mix archive.install hex phx_new 1.5.0
inoas / YouTubeURLFormats.txt
Created January 15, 2022 20:27 — forked from rodrigoborgesdeoliveira/ActiveYouTubeURLFormats.txt
Example of the various YouTube url formats
inoas / Parser.ex
Created June 21, 2021 13:09 — forked from kipcole9/Parser.ex
Parsing a simple expression grammar with maybe quoted strings
defmodule ParseHelpers do
import NimbleParsec
def whitespace() do
|> repeat
def quote_mark(combinator \\ empty()) do
inoas / gpg_fix.txt
Created June 14, 2021 11:19 — forked from cezaraugusto/gpg_fix.txt
fixing `gpg failed to sign data` error on macOS
For troubleshooting, two things to first try:
run `git config --global gpg.program gpg2`, to make sure git uses gpg2 and not gpg
run `echo "test" | gpg2 --clearsign`, to make sure gpg2 itself is working
If that all looks all right, one next thing to try:
run `brew install pinentry` to ensure you have a good tool installed for passphrase entry
If after that install and you re-try git commit and still get the "failed to sign the data" error:
run `gpgconf --kill gpg-agent` to kill any running agent that might be hung