Skip to content

Instantly share code, notes, and snippets.

View spalladino's full-sized avatar
🔷

Santiago Palladino spalladino

🔷
View GitHub Profile
@spalladino
spalladino / mysql-docker.sh
Created December 22, 2015 13:47
Backup and restore a mysql database from a running Docker mysql container
# 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 / can_destroy.rb
Created January 31, 2012 14:42
How to check if object can be destroyed if it has dependent restrict associations
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 / falsehoods-that-ethereum-programmers-believe.md
Last active March 8, 2024 14:34
Falsehoods that Ethereum programmers believe

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 / verboice-demo.js
Created July 4, 2015 18:50
Verboice API demo from node.js
var request = require('request');
var express = require('express');
var http = require('http');
var url = require('url');
// Parse command line options
var program = require('commander');
program
.version("1.0.0")
@spalladino
spalladino / bigdata.md
Last active January 15, 2024 20:36
Apuntes de clase de la materia Big Data dictada por Daniel Yankelevich en FCEN UBA en 2015 1C

Estructuras de datos probabilísticas

  • No devuelven la respuesta exacta, sino una estimación.
  • En algoritmos de streaming, suele ser mejor una respuesta aproximada en el momento a una exacta mucho más tarde

Set membership

  • Estructura Bloom filter para set membership, usa tiempo constante para add y query
  • Hashing (tomar un fingerprint de todos los datos) suele ser mejor técnica que sampling (leer solamente algunos datos al azar), ya que genera solo falsos positivos, no negativos
@spalladino
spalladino / monitor.js
Created October 15, 2017 23:15
Configure ngrok with nodemon for local development
#!/usr/bin/env node
if (process.env.NODE_ENV === 'production') {
throw new Error("Do not use nodemon in production, run bin/www.js directly instead");
}
const nodemon = require('nodemon');
const ngrok = require('ngrok');
// We start an ngrok tunnel to ensure it stays the same for the entire process
@spalladino
spalladino / Loans.sol
Created March 20, 2021 16:57
Strawman for flashloans for flashbots
pragma solidity ^0.7.0;
// Each mining pool that intends to provide flash loans deploys a Loaner contract and transfers ETH to it
// When testing each bundle, the diff in balance in this contract is taking into account for calculating effective gas price
// The contract loans funds only on blocks mined by the miner and on zero-gasprice txs
contract Loaner {
address immutable owner;
constructor(address _owner) {
owner = _owner;
@spalladino
spalladino / cover.py
Created May 21, 2012 01:09
Heuristic for calculating edge clique cover in a graph
class Graph:
def __init__(self, n):
self.n = n
self.adjs = []
self.edges = set()
for i in range(n):
self.adjs.append(set())
def add_edge(self, v, w):
@spalladino
spalladino / web3.js
Created October 16, 2017 16:00
Detect whether a web3 connection is available
// Adapted from https://github.com/MetaMask/faq/blob/master/DEVELOPERS.md#partly_sunny-web3---ethereum-browser-environment-check
window.addEventListener('load', function() {
// Checking if Web3 has been injected by the browser (Mist/MetaMask)
if (typeof web3 !== 'undefined') {
// Use Mist/MetaMask's provider
window.web3 = new Web3(web3.currentProvider);
} else {
// fallback - use your fallback strategy (local node / hosted node + in-dapp id mgmt / fail)
window.web3 = new Web3(new Web3.providers.HttpProvider("http://localhost:8545"));
@spalladino
spalladino / Makefile
Created November 23, 2016 15:40
Proof of concept of Ruby extension written in Crystal
testruby.bundle: testruby.cr
crystal testruby.cr --link-flags "-dynamic -bundle -Wl,-undefined,dynamic_lookup" -o testruby.bundle
irb: testruby.bundle
irb -rtestruby -I.
clean:
rm -rf .crystal testruby.bundle