(by @andrestaltz)
If you prefer to watch video tutorials with live-coding, then check out this series I recorded with the same contents as in this article: Egghead.io - Introduction to Reactive Programming.
# Here a few bash one-liners that helped me analyze / fight a weak DOS attack against debuggable.com. Mostly for future reference. | |
# The attacker was opening lots of tcp connections without sending data, I believe it's called a SYN flood, see: http://tools.ietf.org/html/rfc4987#section-3.2 | |
# Step 0: Check what is going on at port 80 | |
$ netstat -tan | grep ':80 ' | awk '{print $6}' | sort | uniq -c | |
# Step 1: Increase the number of available fds | |
$ ulimit -n 32000 | |
# Step 2: Restart your webserver, for me: |
# graphite-web install is hardcoded in setup.cfg to /opt/graphite | |
sudo mkdir /opt/graphite | |
sudo chown brad.users /opt/graphite | |
# run under python2.7 virtualenv | |
virtualenv --python=python2.7 ~/ve/graphite | |
source ~/ve/graphite/bin/activate | |
# install the necessary python packages (simplejson is for flot graphs) | |
pip install graphite-web carbon whisper django django-tagging uwsgi simplejson |
%% See LICENSE for licensing information. | |
-module(cowboy_debug). | |
-export([onrequest_hook/1]). | |
-export([onresponse_hook/4]). | |
onrequest_hook(Req) -> | |
Method = to_string(extract(cowboy_req:method(Req))), | |
Path = to_string(extract(cowboy_req:path(Req))), | |
Params = params_to_string(extract(cowboy_req:qs_vals(Req))), |
# to generate your dhparam.pem file, run in the terminal | |
openssl dhparam -out /etc/nginx/ssl/dhparam.pem 2048 |
(by @andrestaltz)
If you prefer to watch video tutorials with live-coding, then check out this series I recorded with the same contents as in this article: Egghead.io - Introduction to Reactive Programming.
State machines are everywhere in interactive systems, but they're rarely defined clearly and explicitly. Given some big blob of code including implicit state machines, which transitions are possible and under what conditions? What effects take place on what transitions?
There are existing design patterns for state machines, but all the patterns I've seen complect side effects with the structure of the state machine itself. Instances of these patterns are difficult to test without mocking, and they end up with more dependencies. Worse, the classic patterns compose poorly: hierarchical state machines are typically not straightforward extensions. The functional programming world has solutions, but they don't transpose neatly enough to be broadly usable in mainstream languages.
Here I present a composable pattern for pure state machiness with effects,
type Omit<T, K extends keyof T> = Pick<T, Exclude<keyof T, K>> | |
/* Source: https://github.com/Microsoft/TypeScript/pull/21316#issuecomment-364982638 */ | |
type DiscriminateUnion<Union, TagKey extends keyof Union, TagValue extends Union[TagKey]> = | |
Union extends Record<TagKey, TagValue> ? Union : never | |
type MatchingFunc<A extends { kind: string }, K extends A['kind'], U> = (a: Omit<DiscriminateUnion<A, 'kind', K>, 'kind'>) => U | |
function match<A extends { kind: string }>(discriminant: A) { |
CREATE EXTENSION IF NOT EXISTS "uuid-ossp"; | |
-- My port of https://github.com/kurttheviking/uuid-with-v6-js | |
-- A hacky translation of: | |
-- - http://gh.peabody.io/uuidv6/ | |
-- - https://tools.ietf.org/html/draft-peabody-dispatch-new-uuid-format | |
CREATE OR REPLACE FUNCTION uuid_v1_to_v6(v1 uuid) | |
RETURNS uuid AS $$ | |
DECLARE | |
v6 text; |
-- Based off IETF draft, https://datatracker.ietf.org/doc/draft-peabody-dispatch-new-uuid-format/ | |
create or replace function uuid_generate_v7() | |
returns uuid | |
as $$ | |
begin | |
-- use random v4 uuid as starting point (which has the same variant we need) | |
-- then overlay timestamp | |
-- then set version 7 by flipping the 2 and 1 bit in the version 4 string | |
return encode( |