Thanks to the original blog post: https://equimper.com/blog/how-to-setup-tailwindcss-in-phoenix-1.4
cd assets
npm i --save-dev tailwindcss postcss-loader postcss-import
Thanks to the original blog post: https://equimper.com/blog/how-to-setup-tailwindcss-in-phoenix-1.4
cd assets
npm i --save-dev tailwindcss postcss-loader postcss-import
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] |
#!/usr/bin/env ruby | |
# Run unit test for all added or changed app, lib and test files. | |
# Ex: | |
# * `rtt` will run tests for all files changed since the last commit | |
# * `rtt master` will run tests for all files different from master | |
if ARGV[0] | |
files = `git diff --name-only $(git merge-base HEAD #{ARGV[0]})..$(git rev-parse --abbrev-ref HEAD)`.split("\n") | |
else | |
files = `git status -s`.split("\n").map { |f| f.split(' ').last } |
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.
Disclaimer: This piece is written anonymously. The names of a few particular companies are mentioned, but as common examples only.
This is a short write-up on things that I wish I'd known and considered before joining a private company (aka startup, aka unicorn in some cases). I'm not trying to make the case that you should never join a private company, but the power imbalance between founder and employee is extreme, and that potential candidates would
A checklist for designing and developing internet scale services, inspired by James Hamilton's 2007 paper "On Desgining and Deploying Internet-Scale Services."
require 'socket' | |
# 1. Create | |
# AF_INET means IPv4 (xxx.xxx.xxx.xxx) | |
# SOCK_STREAM means communicating with a stream (TCP) | |
# | |
# Can be simplified to symbols :INET and :STREAM, respectively | |
server = Socket.new(Socket::AF_INET, Socket::SOCK_STREAM) |
A small library for padding strings in JavaScript. Marmalade-free.
![NPM version][shield-npm] ![Node.js version support][shield-node] ![Build status][shield-build] ![Code coverage][shield-coverage]
When developing a program in Ruby, you may sometimes encounter a memory leak. For a while now, Ruby has a facility to gather information about what objects are laying around: ObjectSpace.
There are several approaches one can take to debug a leak. This discusses a time-based approach, where a full memory dump is generated every, say, 5 minutes, during a time that the memory leak is showing up. Afterwards, one can look at all the objects, and find out which ones are staying around, causing the