Skip to content

Instantly share code, notes, and snippets.

@betweenbrain
betweenbrain / life.md
Created February 27, 2016 16:34
Slim 3 Middleware Execution Order Example (last in, first executed)
<?php

require 'vendor/autoload.php';

$app = new \Slim\App();

// Executed last as it's first in (FILE)
$app->add(function ($request, $response, $next) {
	// Execute the routes first
@subfuzion
subfuzion / curl.md
Last active May 3, 2024 09:26
curl POST examples

Common Options

-#, --progress-bar Make curl display a simple progress bar instead of the more informational standard meter.

-b, --cookie <name=data> Supply cookie with request. If no =, then specifies the cookie file to use (see -c).

-c, --cookie-jar <file name> File to save response cookies to.

@O-I
O-I / weighted_random_sampling.md
Last active February 21, 2024 19:02
[TIx 8] Weighted Random Sampling in Ruby

One of the many reasons I love working with Ruby is it has a rich vocabulary that allows you to accomplish your goals with a minimal amount of code. If there isn't a method that does exactly what you want, it's usually possible to build an elegant solution yourself.

Let's take the example of simulating the rolling of a die.

We can represent a die as an array of its faces.

die = [*?⚀..?⚅]
# => ["⚀", "⚁", "⚂", "⚃", "⚄", "⚅"]
@owenallenaz
owenallenaz / caught.js
Last active March 5, 2022 15:30
Showing that nodeJS domains do not catch synchronous errors. Hence the common practice is to enclose them in process.nextTick()
var domain = require("domain");
var d = domain.create();
d.on("error", function() {
console.log("domain caught");
});
try {
d.run(function() {
process.nextTick(function() {
@paul-appsinyourpants
paul-appsinyourpants / Console color in ruby
Created February 18, 2011 22:49
Add color to console logging easily in ruby
COLOR_ESCAPES = {
:none => 0,
:bright => 1,
:black => 30,
:red => 31,
:green => 32,
:yellow => 33,
:blue => 34,
:magenta => 35,
:cyan => 36,