Skip to content

Instantly share code, notes, and snippets.

View smokinggoats's full-sized avatar
:octocat:
Batata é bom

SmokingGoats smokinggoats

:octocat:
Batata é bom
View GitHub Profile
# ZSH Theme
local return_code="%(?..%{$fg[red]%}%? ↵%{$reset_color%})"
if [[ $UID -eq 0 ]]; then
local user_host='{%{$terminfo[bold]$fg[red]%}%n@%m%{$reset_color%}}'
local user_symbol='#'
else
local user_host='{%{$terminfo[bold]$fg[green]%}%n@%m%{$reset_color%}}'
local user_symbol='$'
fi
@smokinggoats
smokinggoats / safeFormatNumber.js
Created April 8, 2020 14:25
Format any string to a simple number
function toNumber(num) {
return Number(String(num).replace(/\./g, ',').replace(/(.+),/g, '$1.').replace(/[^\d.]/g, '').trim())
}
@smokinggoats
smokinggoats / reference.js
Created April 5, 2020 15:21
some this reference for js
function GroceryList(items){
this.items = items;
this.mapItems = (fn) => {
let newItems = [];
// could use map but it would not fit for this example
for (let i = 0; i < this.items.length ; i++){
newItems = [...newItems, fn(this.items[i])];
}
this.items = newItems;
return this;
@smokinggoats
smokinggoats / currencyFormat.js
Created February 4, 2020 18:38
Simple currency formatter
function formatCurrency(number) {
const [integerPart, decimalPart] = `${number}`.split(".");
const chunkSize = 3;
const integerPartArray = integerPart.split("").reverse();
const chunks = Math.ceil(integerPartArray.length / chunkSize);
const formatedInteger = Array.from(new Array(chunks), (_, idx) => {
return integerPartArray
.slice(idx * chunkSize, idx * chunkSize + chunkSize)
.reverse()
.join("");
@smokinggoats
smokinggoats / nestedArrayAndObject.js
Created August 22, 2019 13:12
nestedArrayAndObject.js
function nestedArrayAndObject() {
// refactor this to a single line of destructuring...
const info = {
title: "Once Upon a Time",
protagonist: {
name: "Emma Swan",
enemies: [
{ name: "Regina Mills", title: "Evil Queen" },
{ name: "Cora Mills", title: "Queen of Hearts" },
{ name: "Peter Pan", title: `The boy who wouldn't grow up` },
@smokinggoats
smokinggoats / isort_changed_files.py
Created March 8, 2018 12:17
iSort changed files using git diff
import os
import sys
from subprocess import call, check_output
from isort import SortImports
def isort_all():
path = sys.argv[1]
abs_path = os.path.abspath(path)
@smokinggoats
smokinggoats / speedtest-cli-analysis.py
Last active December 17, 2017 14:20
speedtest-cli csv data analysis collected during a year
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import matplotlib
import os
import datetime
% matplotlib inline
dir_name = os.path.abspath('./')
const WALTER_PRICE = 0.53,
TARE_PRICE = 0.08;
const tareMoney = (bottles) => {
return TARE_PRICE * bottles;
};
const round = (f) => {
return Math.round(f * Math.pow(10, 2)) / Math.pow(10, 2);
};
'''
result:
books
books / nl
books / nl / sf
books / nl / ff
books / il / sf
books / il / ff
'''
@smokinggoats
smokinggoats / RFID-readSerial.py
Created May 11, 2017 14:50
Read / Write some serial data
import serial
import json
import sys
ser = serial.Serial(
port='/dev/ttyUSB0',\
baudrate=9600,\
parity=serial.PARITY_NONE,\
stopbits=serial.STOPBITS_ONE,\
bytesize=serial.EIGHTBITS,\