Skip to content

Instantly share code, notes, and snippets.

@thrilok209
thrilok209 / gasPrice.js
Last active March 23, 2024 13:18
Fetch GasPrice from eth gas station
// in nodeJs
const axios = require('axios')
async function getCurrentGasPrices() {
let response = await axios.get('https://ethgasstation.info/json/ethgasAPI.json')
let prices = {
low: response.data.safeLow / 10,
medium: response.data.average / 10,
high: response.data.fast / 10
}
@malexer
malexer / sqlalchemy_upsert.py
Last active January 26, 2024 14:09
Modelling UPSERT in SQLAlchemy (well actually it is not upsert but speed improvement is significant in comparison with simple session.merge)
# Note: it is a copy of great answer by "mgoldwasser" from Stackoverflow
# Check the original answer here: http://stackoverflow.com/a/26018934/1032439
# Imagine that post1, post5, and post1000 are posts objects with ids 1, 5 and 1000 respectively
# The goal is to "upsert" these posts.
# we initialize a dict which maps id to the post object
my_new_posts = {1: post1, 5: post5, 1000: post1000}
for each in posts.query.filter(posts.id.in_(my_new_posts.keys())).all():