Skip to content

Instantly share code, notes, and snippets.

View j05u3's full-sized avatar
🎯
Focusing

Josue j05u3

🎯
Focusing
View GitHub Profile
@j05u3
j05u3 / segmentTreeWithLazy.cpp
Created June 24, 2015 02:27
Segment Tree with Lazy Propagation, I added the LazyNode struct
// Planchota con modificaciones de Josue
#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
@j05u3
j05u3 / GA_TSP.cpp
Created July 23, 2015 05:28
Genetic algorithm implementation for TSP, the input is a set of 2d points. The algorithm considers that it is possible to walk between any pair of points with euclidean distance (complete graph).
#include <iostream>
#include <vector>
#include <algorithm>
#include <ctime>
#include <cstring>
#include <cmath>
#include <climits>
using namespace std;
@j05u3
j05u3 / E.cpp
Created November 23, 2015 06:21
Solution to problem E
#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
@j05u3
j05u3 / DiffObservableList.java
Last active May 25, 2018 22:26
ObservableList to animate item movements inside a LinearLayout
package pe.tumicro.android.ui.common;
import android.databinding.ListChangeRegistry;
import android.databinding.ObservableList;
import android.support.annotation.MainThread;
import android.support.v7.util.DiffUtil;
import android.support.v7.util.ListUpdateCallback;
import java.util.AbstractList;
@override
Widget build(BuildContext context) {
return Container(
decoration: BoxDecoration(color: Colors.white),
child: buildHomePage("my first function")
);
}
Widget buildHomePage(String title) {
final titleText = Container(
padding: EdgeInsets.all(20),
@j05u3
j05u3 / lifecycle_aware_stream_builder.dart
Last active November 7, 2022 03:07
Lifecycle aware stream builder (flutter). Find more details on https://medium.com/p/a2ae7244af32
import 'dart:async';
import 'package:flutter/widgets.dart';
abstract class StreamBuilderBase<T, S> extends StatefulWidget {
/// Creates a [StreamBuilderBase] connected to the specified [stream].
const StreamBuilderBase({ Key key, this.stream }) : super(key: key);
/// The asynchronous computation to which this builder is currently connected,
@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++;
@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 / 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 / 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();