Skip to content

Instantly share code, notes, and snippets.

@klesouza
klesouza / graytoHex.js
Created April 7, 2016 15:45
Simple javascript method for converting graylevel (0..255 - from white to black) to hexadecimal color
function grayToHex(val) {
if(val >= 0 && val <= 255){
var n = (255 - val).toString(16);
return "#" + n + n + n;
}
}
@klesouza
klesouza / clean_docker_images.bat
Last active June 23, 2016 16:42
Cleaning docker images on Windows
FOR /f "tokens=1" %i IN ('docker images -f "dangling=true" -q') DO docker rmi -f %i
@klesouza
klesouza / clean_docker_images.sh
Last active April 20, 2017 11:08
Bash for cleaning unused docker images
docker rmi $(docker images -f "dangling=true" -q)
@klesouza
klesouza / start-docker.bat
Last active April 20, 2017 11:07
BAT to start docker machine
@echo off
FOR /f "tokens=4" %%i IN ('docker-machine ls --filter "NAME=default"') DO (
IF "%%i"=="Stopped" (
docker-machine start default
@FOR /f "tokens=*" %%j IN ('docker-machine env default') DO @%%j
)
)
@klesouza
klesouza / start-docker.sh
Created April 20, 2017 11:06
Bash to start docker machine
#!/bin/bash
if [[ "$(docker-machine ls --filter 'name=default')" == *"Stopped"* ]]
then
docker-machine start default;
eval $(docker-machine env default);
fi
@klesouza
klesouza / json-masker.js
Created September 5, 2017 20:38
Javascript to filter json properties
<html>
<body>
<textarea name="" id="json" cols="30" rows="10"></textarea>
<input id="filter" />
<textarea name="" id="result" cols="30" rows="10"></textarea>
<button onclick="send()">Filter</button>
</body>
<script type="text/javascript">
var a = {
fare: [
@klesouza
klesouza / bq_schema_gen_dotnet_class.cs
Created February 28, 2019 11:10
C# script to generate BigQuery (BQ) schema from a C# class
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Reflection;
using System.Linq;
using Travix.AirFareDomain;
using System.Collections;
using Newtonsoft.Json;
using System.IO;
@klesouza
klesouza / bq_tfdv.py
Created January 26, 2020 20:56
Analyse BigQuery data with TFDV (tensorflow data validation)
import apache_beam as beam
import pyarrow
import tensorflow_data_validation as tfdv
from tensorflow_metadata.proto.v0 import statistics_pb2
import numpy as np
pipeline_options = beam.pipeline.PipelineOptions.from_dictionary({
'project': '[PROJECT_ID]'
})
@klesouza
klesouza / find_k8s_delete.sh
Created February 3, 2020 14:47
Find all resources in Kubernetes for deletion
kubectl api-resources --verbs="get" --no-headers=true | awk '{ print $1; }' | xargs -I {} sh -c 'for i in `kubectl get $1`; do echo "$1\t$i"; done' sh {} | awk '{ print "kubectl delete " $1 " " $2; }' | grep WHAT_YOUR_ARE_LOOKING_FOR
@klesouza
klesouza / my_git_log.sh
Created April 15, 2020 09:18
Find all your commits in all git repos
#!/bin/bash
find . -type d -depth 1 -exec sh -c 'git --git-dir={}/.git --work-tree=$PWD/{} log --format="%cs %aE %s" --before 2020-04-1 --after 2020-03-02 | grep [YOUR_USER]' \; -print