Skip to content

Instantly share code, notes, and snippets.

@pitzcarraldo
pitzcarraldo / cf-cache.ts
Last active January 23, 2024 09:17
example to use cf cache
async function handleRequest(
c: any,
args: any
): Promise<any> {
const cacheKey = new URL(c.req.url).toString();
const cachedResponse = await caches.default.match(cacheKey);
if (cachedResponse) {
return c.json(await cachedResponse.json());
}
@pitzcarraldo
pitzcarraldo / alias_yarn.sh
Created October 13, 2016 07:07
Way to use yarn more familiar and easy.
#!/bin/sh
# OSX
ln -s /usr/local/bin/yarn /usr/local/bin/ypm
@pitzcarraldo
pitzcarraldo / event-loop-nashorn.js
Created January 28, 2016 14:50 — forked from bripkens/event-loop-nashorn.js
Java 8 Nashorn event loop "polyfill". javax.script.ScriptEngine#eval calls should immediately call window.main to enter the event loop and thus to avoid concurrency issues. The XMLHttpRequest simulation is not yet finished.
(function(context) {
'use strict';
var Timer = Java.type('java.util.Timer');
var Phaser = Java.type('java.util.concurrent.Phaser');
var TimeUnit = Java.type('java.util.concurrent.TimeUnit');
var AsyncHttpClient = Java.type('com.ning.http.client.AsyncHttpClient');
var timer = new Timer('jsEventLoop', false);
var phaser = new Phaser();
@pitzcarraldo
pitzcarraldo / RatioCalculator.java
Created October 21, 2015 00:39
MAB(Multi-Armed Bandits) Java Implementation
/**
* @descreption Calculate impression ratio for Arms by ArmStatistics.
* @author Minkyu Cho(mrnoname@naver.com)
* The logic of this class is based on R code in below article(Figure 4).
* http://mktg455cnu.net/wp-content/uploads/2014/10/scott.pdf
*/
@Slf4j
@Component
public class RatioCalculator {
private static final int SIMULATE_COUNT_BASE = 100;