Skip to content

Instantly share code, notes, and snippets.

@alecgorge
alecgorge / gevent_asyncio_executors.py
Created March 20, 2024 15:45
Example of how to use Temporal's asyncio based SDK in a gevent setting. Uses a separate native thread to execute asyncio code and keep it away from gevent. Activities are still executed on the gevent thread. Tested (but not extensively) with real world workload activities that make heavy use of gevent patched functionality.
import functools
import logging
from concurrent.futures import Future, ThreadPoolExecutor
from typing import Any, Callable, Generic, Tuple, TypeVar
from gevent.threadpool import ThreadPoolExecutor as NativeThreadPoolExecutor # type: ignore[attr-defined]
from typing_extensions import ParamSpec
logger = logging.getLogger(__name__)
https://phish.in/audio/000/014/438/14438.mp3
cache cold: Connect: 0.039889 TTFB: 0.343972 Total time: 44.155656
cache hot : Connect: 0.041104 TTFB: 0.211651 Total time: 3.603023
direct : Connect: 0.079600 TTFB: 0.416767 Total time: 6.376287
https://phish.in/audio/000/014/447/14447.mp3
cache cold: Connect: 0.039804 TTFB: 0.343956 Total time: 4.963368
cache hot : Connect: 0.039804 TTFB: 0.207647 Total time: 0.699860
@alecgorge
alecgorge / page_replacement.py
Last active July 12, 2021 23:09 — forked from pallabpain/page_replacement
Page Replacement simulation in Python w/fixed optimal algorithm
a = [1,2,3,4,2,1,5,6,2,1,2,3,7,6,3,2,1,2,3,6]
n = len(a)
m = 2
#Function to accept reference string and frame size.
def accept():
global a,n,m
a = []
n = input("\n Enter the size of reference string : ")
for i in range(n):

Keybase proof

I hereby claim:

  • I am alecgorge on github.
  • I am alecgorge (https://keybase.io/alecgorge) on keybase.
  • I have a public key whose fingerprint is 265A 6C16 3686 84BA 151A D2EA BAD8 D736 A0A4 6B6E

To claim this, I am signing this object:

<form method='post' action="http://localhost:3000/api/images/new" enctype="multipart/form-data">
<input type="file" name="image" />
<input type="submit" />
</form>
@alecgorge
alecgorge / iguana.conf
Created January 19, 2014 04:36
iguana nginx conf
upstream iguana_node {
server localhost:9000;
}
upstream iguana_phantom {
server localhost:8888;
}
server {
listen 80;
@alecgorge
alecgorge / Create iOS Icons.jsx
Last active December 23, 2015 16:59 — forked from twonjosh/Create iOS Icons.jsx
iOS 7 sizes
// Photoshop Script to Create iPhone Icons from iTunesArtwork
//
// WARNING!!! In the rare case that there are name collisions, this script will
// overwrite (delete perminently) files in the same folder in which the selected
// iTunesArtwork file is located. Therefore, to be safe, before running the
// script, it's best to make sure the selected iTuensArtwork file is the only
// file in its containing folder.
//
// Copyright (c) 2010 Matt Di Pasquale
// Added tweaks Copyright (c) 2012 by Josh Jones http://www.appsbynight.com
@alecgorge
alecgorge / generate_wget_wwdc2013.js
Last active December 18, 2015 13:48
A script to run from the console that generates a wget compatible list of downloads of the WWDC2013 releases, categorized by track. You can change PDF to HD or SD to download videos.
(function ($) {
return $('a').filter(function () {
return $(this).text() == "PDF";
}).map(function () {
var dl_free_name = $(this).attr('href').substring(0, $(this).attr('href').length - 5);
var ext = dl_free_name.substring(dl_free_name.length - 3);
var track = $(this).parents('.session').find('.track').text();
var title = $(this).parents('.session').find('.title').text().replace(/[^a-zA-Z0-9-_ ]+/g, '');
return 'wget "' + dl_free_name + '" -O "[' + track + '] ' + title + '.' + ext + '"';
}).toArray().join("\n");
int MakeSendPacket(int BoxType, int TeamNumber, int RecTeamNumber) {
// 0000000000000011 BoxType << 12
// 0011000000000000
int Packed = BoxType << 12;
Packed = Packed | (TeamNumber << 6);
Packed = Packed | RecTeamNumber;
return Packed;
}
<?php
function mb_str_replace($search, $replace, $subject) {
if(is_array($subject)) {
$ret = array();
foreach($subject as $key => $val) {
$ret[$key] = mb_str_replace($search, $replace, $val);
}
return $ret;
}