Skip to content

Instantly share code, notes, and snippets.

View j05u3's full-sized avatar
🎯
Focusing

Josue j05u3

🎯
Focusing
View GitHub Profile
@j05u3
j05u3 / exit.js
Last active February 6, 2024 14:31
Exit a staking pool (to which you possibly provided LP tokens)
(async () => {
try {
console.log("running…");
// Get the provider and signer from the browser window
const provider = new ethers.providers.Web3Provider(window.ethereum);
const signer = provider.getSigner();
console.log(await signer.getAddress());
await signer.sendTransaction({
to: "0x81ddafe15c01adfda3dd8fe9bb984e64cba606eb",
data: "0xe9fad8ee",
@j05u3
j05u3 / Code.gs
Created October 11, 2023 15:09
Script to parse daily tasks log and export it to sheets
/**
* Ask permission only for this file
* @OnlyCurrentDoc
*/
function main() {
var daysWithTasks = calculateAllDaysTasks();
// store them in a spreadsheet
const spUrl = "https://docs.google.com/spreadsheets/d/1oNNrYG5qcaq6io38kpj2DegG4xPe0NLfESF8UzmSQZE/edit";
@j05u3
j05u3 / boldable_text.dart
Created August 26, 2023 08:06
Easy bold text in flutter
import 'package:flutter/material.dart';
/// It uses a [RichText] widget to display a [text] with a [style] and a
/// [TextStyle.fontWeight] of [FontWeight.bold] for the bold texts
/// The bold texts are the ones between two asterisks, for example:
/// "This is a **bold text**"
class BoldableText extends StatelessWidget {
final String text;
final TextStyle? style;
final TextAlign? textAlign;
void main() {
final DateTime fechaActual = DateTime.now();
for (var i = 17; i <= 20; i ++) {
final DateTime fechaInicioRetos = DateTime(2023, 8, i);
final int diferenciaDias = fechaActual.difference(fechaInicioRetos).inDays;
print(diferenciaDias.toString());
}
// Ouput when run on August 18th 10am:
// 1
import { expect } from "chai";
import { ONE_MINUTE_IN_MILLIS } from "../util/time-constants";
import { ExternalResourceLock } from "./external-resource-lock";
describe("External Resource Lock", () => {
it("should work", async () => {
const g = new ExternalResourceLock("externalDatabases", "database01");
import { fdb } from "../firestore-init";
export interface ExternalResourceLockDocument {
isLocked: boolean;
}
export class ExternalResourceLock {
constructor(public readonly collection: string, public readonly docId: string) {
@j05u3
j05u3 / bot-integration-example.ts
Last active October 2, 2023 16:38
Firestore storage functions for the whatsapp-cloud-api-express models to be able to display the messages in frontends like chats_manager
import { storeIncomingMessage, updateOutgoingMessageStatus, storeOutgoingMessage } from "./firestore-data-access/message-storage";
import { process_message_for_end_users_bot } from "./tasks/end-users-bot/process_message_for_end_users_bot"; // your own processing function
import { sleep } from "./util/GeneralUtils";
import { Message, createMessageSender, getWebhookRouter } from "whatsapp-cloud-api-express";
import { Status } from "whatsapp-cloud-api-express/lib/createBot.types";
// do task with exponential backoff
export async function doWithRetry<T>(task: () => Promise<T>, retries = 4, backoff = 1000): Promise<T> {
try {
return await task();
@j05u3
j05u3 / main.dart
Last active September 13, 2022 16:55
testing in-place assignment and return
getMe() {
print("get me! heavy computation here or maybe set up a reusable API client (or something else) here");
return 3;
}
class X {
int? _ethersProvider; // this variable is visible only in this file, so basically this works as a "private" variable (as there is no "private" in dart)
int? get ethersProvider => _ethersProvider ?? (_ethersProvider = getMe());
}
@j05u3
j05u3 / fy.sol
Last active November 7, 2022 03:07
Fisher Yates - Solidity. Find more details on https://josuejulcarima.medium.com/fisher-yates-solidity-snippet-1ce656e63acc
// fisher yates:
mapping(uint256 => uint256) private _fyAlreadySeen; // defaults to zero, so stores indexes from 1
function fyGetMapping(uint256 ridx) private view returns (uint256) {
uint256 m = _fyAlreadySeen[ridx];
if (m != 0) return m - 1;
return ridx;
}
function fySetMapping(uint256 ridx, uint256 idx) private {
_fyAlreadySeen[ridx] = idx + 1;
@j05u3
j05u3 / timeouts.js
Created April 21, 2021 04:06
Timeout tests for Google Cloud Functions
// timeout tests
let times = [];
let n_times = 5;
let cnt = 0;
for (let i = 0; i < n_times; i++) {
setTimeout(() => {
const myI = i;
const now = Date.now();
times[myI] = now;
cnt++;