Skip to content

Instantly share code, notes, and snippets.

@cjcbusatto
cjcbusatto / minimal-react.js
Created November 27, 2022 19:51
Minimal React example
const React = (() => {
let hooks = [];
let idx = 0;
function useState(initValue) {
let state = hooks[idx] || initValue;
let _idx = idx;
let setState = (newValue) => {
hooks[_idx] = newValue;
};
@cjcbusatto
cjcbusatto / wait_for_http_200.sh
Created December 22, 2021 13:27 — forked from rgl/wait_for_http_200.sh
Wait for an HTTP endpoint to return 200 OK with Bash and curl
bash -c 'while [[ "$(curl -s -o /dev/null -w ''%{http_code}'' localhost:9000)" != "200" ]]; do sleep 5; done'
# also check https://gist.github.com/rgl/c2ba64b7e2a5a04d1eb65983995dce76
@cjcbusatto
cjcbusatto / template_update_using_forloop.sql
Created September 15, 2021 12:20
Template of an update using a for loop in plpgsql
do $$
declare
data_values record;
begin
for data_values in (select * from table)
loop
update table
set column_value = (select column_value from another_table where id = data_values.id)
where id = data_values.id;
end loop;

Aligning images

left alignment

This is the code you need to align images to the left:

@cjcbusatto
cjcbusatto / count_dir.sh
Created February 22, 2020 19:55
Count files inside a directory
function count_dir {
ls -1 $1 | wc -l
}
@cjcbusatto
cjcbusatto / .zshrc
Created December 23, 2019 12:33
My ~/.zhrc configuration
export JAVA_HOME="/Applications/Android Studio.app/Contents/jre/jdk/Contents/Home"
export ANDROID_HOME=$HOME/Library/Android/sdk
export PATH="$HOME/bin:/usr/local/bin:$JAVA_HOME/bin:$ANDROID_HOME/platform-tools:$ANDROID_HOME/emulator:$PATH"
# Path to your oh-my-zsh installation.
export ZSH="/Users/cbusa/.oh-my-zsh"
export NVM_DIR="${XDG_CONFIG_HOME/:-$HOME/.}nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"
# functions
@cjcbusatto
cjcbusatto / create-node.sh
Last active December 23, 2019 12:29
Function to scaffold node projects faster
# This gist is based on https://philna.sh/blog/2019/01/10/how-to-start-a-node-js-project/
# 1. Configure your npm
npm set init.author.name "Your name"
npm set init.author.email "your@email.com"
npm set init.author.url "https://your-url.com"
npm set init.license "MIT"
npm set init.version "1.0.0"
# 2. Include this function to your bash_profile, e.g. ~/.zshrc
function create-node {
@cjcbusatto
cjcbusatto / setup_airbnb_codestyle.sh
Last active December 12, 2019 17:13
Include Prettier, ESLint and Airbnb code style to a NodeJS project on Visual Studio Code
# This gist is based on https://blog.echobind.com/integrating-prettier-eslint-airbnb-style-guide-in-vscode-47f07b5d7d6a
# Download the ESLint and Prettier extensions for VSCode.
code --install-extension esbenp.prettier-vscode
code --install-extension dbaeumer.vscode-eslint
# Install the ESLint and Prettier libraries into our project. In your project’s root directory, you will want to run:
npm install -D eslint prettier
# Install the Airbnb config. If you’re using npm 5+, you can run this shortcut to install the
# config and all of its dependencies:
@cjcbusatto
cjcbusatto / runPgAdminDocker.sh
Created December 11, 2019 17:31
pgAdmin running on Docker
docker container run \
-e PGADMIN_DEFAULT_EMAIL=claudio@email.com \
-e PGADMIN_DEFAULT_PASSWORD=123456 \
-p 80:80 \
dpage/pgadmin4
# pgAdmin4 will be available on http://localhost:80
@cjcbusatto
cjcbusatto / post_json_request.py
Created August 24, 2019 14:10
POST request with JSON body in Python using requests library
import requests
import json
url = "http://localhost:8080"
data = {'key': 'value'}
headers = {'Content-type': 'application/json', 'Accept': 'text/plain'}
r = requests.post(url, data=json.dumps(data), headers=headers)