Skip to content

Instantly share code, notes, and snippets.

View LeoBorai's full-sized avatar

Leo Borai LeoBorai

View GitHub Profile
@LeoBorai
LeoBorai / remove-all-from-docker.sh
Created November 19, 2020 12:32 — forked from beeman/remove-all-from-docker.sh
Remove all from Docker
# Stop all containers
docker stop `docker ps -qa`
# Remove all containers
docker rm `docker ps -qa`
# Remove all images
docker rmi -f `docker images -qa `
# Remove all volumes
echo "Removing containers :" && if [ -n "$(docker container ls -aq)" ]; then docker container stop $(docker container ls -aq); docker container rm $(docker container ls -aq); fi; echo "Removing images :" && if [ -n "$(docker images -aq)" ]; then docker rmi -f $(docker images -aq); fi; echo "Removing volumes :" && if [ -n "$(docker volume ls -q)" ]; then docker volume rm $(docker volume ls -q); fi; echo "Removing networks :" && if [ -n "$(docker network ls | awk '{print $1" "$2}' | grep -v 'ID\|bridge\|host\|none' | awk '{print $1}')" ]; then docker network rm $(docker network ls | awk '{print $1" "$2}' | grep -v 'ID\|bridge\|host\|none' | awk '{print $1}'); fi;
@LeoBorai
LeoBorai / mysql.sql
Created November 19, 2020 01:01 — forked from logrusorgru/mysql.sql
SQL: uniqueness, automatic created_at, updated_at refresh + soft delete. SQLite, PostgreSQL, MySQL
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
-- --
-- mysql --
-- --
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
--
-- mysql <http://sqlfiddle.com/#!9/91afb5/2>
-- note: sqlfiddle is very stupid
@LeoBorai
LeoBorai / split_string_slice_chunks.rs
Created October 17, 2020 05:14
Rust - Split string slice in chunks
use std::str;
fn main() {
let subs = "&#8204;&#8203;&#8204;&#8203;&#8204;&#8203;&#8203;&#8204;&#8203;&#8204;".as_bytes()
.chunks(7)
.map(str::from_utf8)
.collect::<Result<Vec<&str>, _>>()
.unwrap();
println!("{:?}", subs);
@LeoBorai
LeoBorai / payload.json
Last active October 19, 2020 15:40
Updates, Updates, Updates
[
{
"date": "2020-10-19T15:40:04.592Z",
"reqBodyJson": {
"coord": {
"lon": -0.13,
"lat": 51.51
},
"weather": [
{
@LeoBorai
LeoBorai / foo.json
Last active October 6, 2020 15:03
Hello World Examples
2020-10-06T15:03:03.751Z
@LeoBorai
LeoBorai / eapi.rs
Created September 1, 2020 03:30 — forked from fredhsu/eapi.rs
Using Rust/Hyper to do a HTTP Post with JSON
extern crate hyper;
extern crate core;
use std::io::Read;
use hyper::Client;
use hyper::header::Connection;
use hyper::header::Basic;
use hyper::header::Headers;
use core::str::FromStr;
@LeoBorai
LeoBorai / testing_cors_curl.sh
Created August 11, 2020 01:50
testing_cors_curl
curl -X OPTIONS 'http://0.0.0.0:7878' -H "Origin: my.site.origin" -H "Access-Control-Request-Method: GET"
package main
import (
"fmt"
"net/http"
"log"
)
func main() {
// A slice of sample websites
@LeoBorai
LeoBorai / rust_find_and_remove_piece_of_str.rs
Created August 9, 2020 19:44
Rust - Find and Remove piece of string
fn main() {
const NAMESPACE_LENGTH: usize = 9;
let path = "/api/v1/catalog/GetNames";
// find index of catalog namespace
match path.find("/catalog/") {
Some(index) => {
let unused = NAMESPACE_LENGTH + index;