Skip to content

Instantly share code, notes, and snippets.

View alexisvisco's full-sized avatar
🧗
Climber.

Alexis Viscogliosi alexisvisco

🧗
Climber.
View GitHub Profile
@alexisvisco
alexisvisco / hstore_gorm.go
Last active January 26, 2024 07:12
a gorm v2 hstore implementation that just works ...
package hstore
import (
"context"
"database/sql"
"database/sql/driver"
"encoding/json"
"gorm.io/gorm"
"gorm.io/gorm/clause"
"gorm.io/gorm/schema"
{"$schema":"http://json-schema.org/draft-07/schema#","$id":"http://json-schema.org/draft-07/schema#","type":"object","title":"The Root Schema","required":["application"],"properties":{"application":{"$id":"#/properties/application","type":"object","title":"The Application Schema","required":["name","project","cloud_region","publicly_accessible","dockerfile"],"properties":{"name":{"$id":"#/properties/application/properties/name","type":"string"},"project":{"$id":"#/properties/application/properties/project","type":"string"},"cloud_region":{"$id":"#/properties/application/properties/cloud_region","type":"string","enum":["aws/us-east-2","aws/us-east-1","aws/us-west-1","aws/us-west-2","aws/ap-east-1","aws/ap-south-1","aws/ap-northeast-3","aws/ap-northeast-2","aws/ap-southeast-1","aws/ap-southeast-2","aws/ap-northeast-1","aws/ca-central-1","aws/cn-north-1","aws/cn-northwest-1","aws/eu-central-1","aws/eu-west-1","aws/eu-west-2","aws/eu-west-3","aws/eu-north-1","aws/me-south-1","aws/sa-east-1","aws/us-gov-east-1","a
use std::collections::{HashMap, HashSet};
use std::env::args;
use std::fs::File;
use std::io::{BufRead, BufReader};
use std::str;
use std::sync::mpsc;
use std::thread;
const BUFFER_SIZE: usize = 4096;
@alexisvisco
alexisvisco / consume_buffer.rs
Last active December 1, 2019 18:44
Read a BufReader with a BUFFER_SIZE and with each read ending with a \n
fn consume_buffer(buffer_reader: &mut BufReader<&File>) -> Option<String> {
let mut full_line = String::new();
'outer: loop {
match buffer_reader.fill_buf() {
Ok(buffer) => {
let buffer_str = String::from_utf8(buffer.to_vec()).unwrap_or(String::new());
// A previous buffer has been read.
// It was without '\n' termination so it must read until it find a '\n'.
if !full_line.is_empty() {

Keybase proof

I hereby claim:

  • I am alexisvisco on github.
  • I am alexisvisco (https://keybase.io/alexisvisco) on keybase.
  • I have a public key ASAG6l2ZXTGW0qqhUbpMjFysGAiXtip4oeeCjJjKyWELwwo

To claim this, I am signing this object:

@alexisvisco
alexisvisco / logfmt.go
Created August 17, 2019 14:58
logfmt parser in go that return map[string]string
func ParseLogfmt(msg string) map[string]string {
type kv struct {
key, val string
}
var pair *kv = nil
pairs := make(map[string]string)
buf := bytes.NewBuffer([]byte{})
openapi: "3.0.0"
info:
version: 1.0.0
title: Expected API spec
servers:
- url: http://localhost:{port}/{basePath}
description: "Development server"
variables:
package ainsi
//
//This package is a util library to provide human writeable ainsi codes for terminals.
//Author: Alexis Viscogliosi
//
import "fmt"
use std::sync::mpsc;
use std::thread;
use std::time::Duration;
use std::sync::Arc;
use std::sync::Mutex;
use std::clone;
use std::sync::mpsc::Sender;
struct JobStatus {
jobs_completed: u32,
#[macro_use]
mod cli;
mod commands;
extern crate termios;
use std::io;
use std::io::Read;
use std::io::Write;