⤵
- Install https://pngquant.org/
$ brew install pngquant
# 2023-11-27 MIT LICENSE | |
Here's the open source version of my ChatGPT game MonkeyIslandAmsterdam.com. | |
It's an unofficial image+text-based adventure game edition of Monkey Island in Amsterdam, my home town. | |
Please use it however you want. It'd be nice to see more ChatGPT-based games appear from this. If you get inspired by it, please link back to my X https://x.com/levelsio or this Gist so more people can do the same! | |
Send me your ChatGPT text adventure game on X, I'd love to try it! |
⤵
$ brew install pngquant
require 'benchmark/ips' | |
require 'redis' | |
class MethodProfiler | |
def self.patch(klass, methods, name) | |
patches = methods.map do |method_name| | |
<<~RUBY | |
unless defined?(#{method_name}__mp_unpatched) | |
alias_method :#{method_name}__mp_unpatched, :#{method_name} | |
def #{method_name}(*args, &blk) | |
unless prof = Thread.current[:_method_profiler] |
#!/bin/sh | |
# 1) Install Xcode 11 | |
# 2) Install command line tools: `xcode-select --install` | |
# 3) Install HomeBrew | |
# 4) brew tap cartr/qt4 && brew install cartr/qt4/openssl@1.0 subversion rbenv | |
# 5) Setup rbenv | |
# 6) Run this command | |
PKG_CONFIG_PATH="$(brew --prefix cartr/qt4/openssl@1.0)/lib/pkgconfig" \ |
The following are examples of the four types rate limiters discussed in the accompanying blog post. In the examples below I've used pseudocode-like Ruby, so if you're unfamiliar with Ruby you should be able to easily translate this approach to other languages. Complete examples in Ruby are also provided later in this gist.
In most cases you'll want all these examples to be classes, but I've used simple functions here to keep the code samples brief.
This uses a basic token bucket algorithm and relies on the fact that Redis scripts execute atomically. No other operations can run between fetching the count and writing the new count.
// Usage: | |
// | |
// function loader() { | |
// return new Promise((resolve) => { | |
// if (process.env.LAZY_LOAD) { | |
// require.ensure([], (require) => { | |
// resolve(require('./SomeComponent').default); | |
// }); | |
// } | |
// }); |
daemon off; | |
# Heroku dynos have at least 4 cores. | |
worker_processes <%= ENV['NGINX_WORKERS'] || 4 %>; | |
events { | |
use epoll; | |
accept_mutex on; | |
worker_connections 1024; | |
} |
require 'aws-sdk' | |
require 'elasticsearch' | |
require 'httparty' | |
require 'socket' | |
ec2 = AWS::EC2.new | |
# elasticsearch_cluster is just an array of ip's, so you could manually replace or use your api of choice to get them | |
elasticsearch_cluster = ec2.instances.with_tag('es_cluster_name', 'es_test').filter('instance-state-name', 'running').map{ |i| i.private_ip_address } | |
start_time = Time.now.to_i |
# speed up pluck | |
class ActiveRecord::Relation | |
class RailsDateTimeDecoder < PG::SimpleDecoder | |
def decode(string, tuple=nil, field=nil) | |
if Rails.version >= "4.2.0" | |
@caster ||= ActiveRecord::Type::DateTime.new | |
@caster.type_cast_from_database(string) | |
else |
/** | |
* Fancy ID generator that creates 20-character string identifiers with the following properties: | |
* | |
* 1. They're based on timestamp so that they sort *after* any existing ids. | |
* 2. They contain 72-bits of random data after the timestamp so that IDs won't collide with other clients' IDs. | |
* 3. They sort *lexicographically* (so the timestamp is converted to characters that will sort properly). | |
* 4. They're monotonically increasing. Even if you generate more than one in the same timestamp, the | |
* latter ones will sort after the former ones. We do this by using the previous random bits | |
* but "incrementing" them by 1 (only in the case of a timestamp collision). | |
*/ |