Skip to content

Instantly share code, notes, and snippets.

Avatar
🔷

Santiago Palladino spalladino

🔷
View GitHub Profile
@spalladino
spalladino / mysql-docker.sh
Created Dec 22, 2015
Backup and restore a mysql database from a running Docker mysql container
View mysql-docker.sh
# Backup
docker exec CONTAINER /usr/bin/mysqldump -u root --password=root DATABASE > backup.sql
# Restore
cat backup.sql | docker exec -i CONTAINER /usr/bin/mysql -u root --password=root DATABASE
@spalladino
spalladino / falsehoods-that-ethereum-programmers-believe.md
Last active Dec 3, 2020
Falsehoods that Ethereum programmers believe
View falsehoods-that-ethereum-programmers-believe.md

Falsehoods that Ethereum programmers believe

I recently stumbled upon Falsehoods programmers believe about time zones, which got a good laugh out of me. It reminded me of other great lists of falsehoods, such as about names or time, and made me look for an equivalent for Ethereum. Having found none, here is my humble contribution to this set.

About Gas

Calling estimateGas will return the gas required by my transaction

Calling estimateGas will return the gas that your transaction would require if it were mined now. The current state of the chain may be very different to the state in which your tx will get mined. So when your tx i

@spalladino
spalladino / setup-relayer.md
Last active Nov 18, 2020
Manual script for setting up a GSNv1 relayer
View setup-relayer.md

Manual setup for a GSN relayer

⚠️ This setup is only good for GSNv1. Head over to https://docs.opengsn.org for the latest setup for GSNv2.

Install nginx and certbot

sudo add-apt-repository universe
sudo add-apt-repository ppa:certbot/certbot
sudo apt-get update
sudo apt-get install nginx software-properties-common certbot python-certbot-nginx
@spalladino
spalladino / revert.ts
Created Sep 11, 2020
Get the revert reason before sending an Ethereum transaction if the transaction would fail
View revert.ts
export async function tryGetRevertReason(to: string, from: string, data: string): Promise<string | undefined> {
const provider = ethers.getDefaultProvider();
const tx = { to, from, data };
try {
await provider.estimateGas(tx);
} catch {
const value = await provider.call(tx);
return hexDataLength(value) % 32 === 4 && hexDataSlice(value, 0, 4) === '0x08c379a0'
? defaultAbiCoder.decode(['string'], hexDataSlice(value, 4))
: undefined;
@spalladino
spalladino / deploy-function.js
Created Sep 27, 2020
Deploy a subset of AWS SAM functions bypassing CloudFormation for a faster development cycle
View deploy-function.js
#! /usr/bin/env node
const TEMPLATE_FILENAME = 'template.yaml';
const WEBPACK_CONFIG = './api/webpack.config.js';
const WEBPACK_CONTEXT = './api';
const STACKNAME = process.env.STACKNAME;
const { Lambda, CloudFormation } = require('aws-sdk');
const { yamlParse } = require('yaml-cfn');
const { readFileSync } = require('fs');
@spalladino
spalladino / assume-role.sh
Created Aug 25, 2020
Bash scripts for MFA sign in to AWS in the console
View assume-role.sh
AWS_ACCOUNT_ID= # aws account
AWS_USER_PROFILE= # profile in aws/credentials to your access key
AWS_REGION= # default region
AWS_IAM_NAME= # your iam name in the aws account
ARN_OF_ROLE= # the role you want to assume
ARN_OF_MFA=arn:aws:iam::$AWS_ACCOUNT_ID:mfa/$AWS_IAM_NAME
MFA_TOKEN_CODE=$1
read AWS_ACCESS_KEY_ID AWS_SECRET_ACCESS_KEY AWS_SESSION_TOKEN <<< \
@spalladino
spalladino / AdminUpgradeabilityProxy.abi.json
Created May 20, 2019
ABI for ZeppelinOS AdminUpgradeabilityProxy as of zos-lib@2.3.0
View AdminUpgradeabilityProxy.abi.json
[
{
"constant": false,
"inputs": [
{
"name": "newImplementation",
"type": "address"
}
],
"name": "upgradeTo",
@spalladino
spalladino / stats.py
Created Jan 5, 2014
Count number of lines of code per language per week in git repository using cloc
View stats.py
import csv
import os
import sys
from os.path import isfile
from datetime import date, timedelta
from subprocess import call, check_output
# Script expects that each project is in a folder with the same name in the working directory
PROJECTS = ['my-project', 'another-project']
@spalladino
spalladino / can_destroy.rb
Created Jan 31, 2012
How to check if object can be destroyed if it has dependent restrict associations
View can_destroy.rb
class ActiveRecord::Base
def can_destroy?
self.class.reflect_on_all_associations.all? do |assoc|
assoc.options[:dependent] != :restrict || (assoc.macro == :has_one && self.send(assoc.name).nil?) || (assoc.macro == :has_many && self.send(assoc.name).empty?)
end
end
end
@spalladino
spalladino / count-repos.py
Last active Feb 21, 2020
Estimate number of repositories that match a code search
View count-repos.py
from http.client import HTTPSConnection
from base64 import b64encode
from json import loads
from sys import exit, argv, stderr
from time import sleep
import urllib3
# Settings
PRINT_REPOS = True
You can’t perform that action at this time.