Skip to content

Instantly share code, notes, and snippets.

@mgiacomini
mgiacomini / rails_fast_csv_importer.rb
Created September 10, 2017 01:15
use copy command to fast imports
db_conn = ActiveRecord::Base.connection.raw_connection
copy_statement = 'COPY forecasts FROM STDIN'
file_path = '/tmp/forecast.csv'
db_conn.copy_data(copy_statement) do
CSV.foreach(file_path, headers: true) do |row|
db_conn.put_copy_data(row.fields + [Time.zone.now])
end
end
@mgiacomini
mgiacomini / results.sh
Created November 18, 2017 19:32
results
#!/bin/bash
echo "#####" >> result.txt
echo "L3 Bandwidth" >> result.txt
for i in 32 33 64 65 128 129 256 257 512 1000 2000
do
echo $i >> result.txt
likwid-perfctr -f -C 0 -g L3 -m ./invmat -i 10 -r $i -o saida.txt | grep "L3 bandwidth" >> result.txt
#likwid-perfctr -f -C 0 -g L3 ./cgSolver $num 7 -i 10 -o saida.txt
@mgiacomini
mgiacomini / clean_docker.sh
Created December 15, 2017 12:20
clean docker
#!/bin/bash
# Stop all containers
docker stop $(docker ps -a -q)
# Delete all containers
docker rm $(docker ps -a -q)
# Delete all images
docker rmi $(docker images -q)
@mgiacomini
mgiacomini / Flexible Dockerized Phoenix Deployments.md
Created February 14, 2018 17:20 — forked from jswny/Flexible Dockerized Phoenix Deployments.md
A guide to building and running zero-dependency Phoenix (Elixir) deployments with Docker. Works with Phoenix 1.2 and 1.3.

Prelude

I. Preface and Motivation

This guide was written because I don't particularly enjoy deploying Phoenix (or Elixir for that matter) applications. It's not easy. Primarily, I don't have a lot of money to spend on a nice, fancy VPS so compiling my Phoenix apps on my VPS often isn't an option. For that, we have Distillery releases. However, that requires me to either have a separate server for staging to use as a build server, or to keep a particular version of Erlang installed on my VPS, neither of which sound like great options to me and they all have the possibilities of version mismatches with ERTS. In addition to all this, theres a whole lot of configuration which needs to be done to setup a Phoenix app for deployment, and it's hard to remember.

For that reason, I wanted to use Docker so that all of my deployments would be automated and reproducable. In addition, Docker would allow me to have reproducable builds for my releases. I could build my releases on any machine that I wanted in a contai

@mgiacomini
mgiacomini / opportunities.gql
Last active March 8, 2018 18:39
Graphql example for create new opportunities
mutation {
createOpportunity(
contact: {
name: "mauricio",
email: "[email protected]",
phone: "41 995 000 315",
age: 35
},
loan_value: 100000.0,
realty_value: 200000.0,
@mgiacomini
mgiacomini / new_decode.py
Created April 2, 2018 20:22
walter horning map
data = json.load(open("medidas.json"))
def is_json(myjson):
try:
json_object = json.loads(myjson)
except ValueError:
return False
return json_object
def decode_json(json):
@mgiacomini
mgiacomini / cet.js
Created April 12, 2018 19:39
custo efetivo anual
var MAX_CET = 100000;
var valorCET = 0;
while (true) {
var valorTotal = 0;
for (mes = 1; mes <= gPrazoPagamento; mes++) {
var valorCalculado = parcelasArray[mes - 1].valorParcela / Math.pow((1.0 + valorCET), mes);
valorTotal = valorTotal + valorCalculado;
@mgiacomini
mgiacomini / macosx_fix.md
Created April 24, 2018 13:10
MacOSx Update Fix:

MacOSx Update Fix:

  1. Reinicializa em Modo Recovery (Cmd-R), e entra em Utilities -> Terminal

  2. Executa uma busca do pacote em uma pasta temporária: find / -name OSInstall.mpkg

  3. Cria a pasta correta: mkdir -p "/Volumes/Macintosh HD/System/Installation/Packages"

@mgiacomini
mgiacomini / build_export_query.ex
Created May 9, 2018 14:21
export query for ecto
def build_export_query(user, batch_size \\ 500)
columns = ~w(id name amount amount_currency cycle first_bill_date type type_description)
query = """
COPY (
SELECT #{Enum.join(columns, ",")}
FROM subscriptions
WHERE archived = false
AND user_id = #{user.id}
) to STDOUT WITH CSV DELIMITER ',';
@mgiacomini
mgiacomini / manual.md
Last active June 20, 2018 00:06
Deploy kubernetes in Google Cloud

Before you begin

  1. gcloud config set project [PROJECT_ID]
  2. gcloud config set compute/zone [COMPUTE_ZONE]
  3. gcloud components update

Cluster

Hire resources

  1. Create a container cluster: gcloud container clusters create [CLUSTER_NAME]
  2. Ensure was created: gcloud container clusters list