Skip to content

Instantly share code, notes, and snippets.

@clhenrick
clhenrick / .gitignore
Last active January 11, 2024 12:33
Node.JS script to aggregate NYC vehicle collision data into a hexagonal grid and compute the ck means for each cell using Turf.JS and Simple Statistics.JS
node_modules/
.DS_Store
@imliam
imliam / take.php
Last active January 15, 2020 14:30
Run functions consecutively by piping through the result of one into the next.
<?php
if (! function_exists('take')) {
/**
* Run functions consecutively by piping through the result of one
* into the next.
*
* @param mixed $value A value
*
* @return object
*/
import React, { Component } from 'react'
import { TransitionGroup, CSSTransition } from 'react-transition-group'
import {
BrowserRouter as Router,
Switch,
Route,
Link,
Redirect
} from 'react-router-dom'
@james2doyle
james2doyle / slim-stream-route.php
Created January 10, 2018 06:05
Create a streaming download of a large file with Slim PHP using the build in Stream class
<?php
use Slim\Http\Request;
use Slim\Http\Response;
use Slim\Http\Stream;
$app->get('/stream', function (Request $request, Response $response, array $args) {
// a 100mb file
$path = '../public/files/document.pdf';
@nicolashery
nicolashery / .gitignore
Last active September 17, 2023 16:58
TypeScript React JSDoc
node_modules
dist
@haampie
haampie / collections.php
Last active September 4, 2023 14:30
Collections
<?php
final class User
{
private $name;
public function __construct(string $name)
{
$this->name = $name;
}
@realyze
realyze / pizza.js
Last active February 14, 2018 19:40
Pizza challenge
const defer = (res, ms) => new Promise(resolve => setTimeout(() => resolve(res), ms));
const makeDough = () => defer({add: () => {}}, 500);
const makeSauce = () => defer({determineCheese: () => 'cheddar'}, 250);
const grateCheese = () => defer({type: 'cheddar'}, 150);
async function makePizza(sauceType = 'red') {
const pDough = makeDough();
@mindplay-dk
mindplay-dk / collections.md
Last active June 6, 2021 14:37
Linear collection workflow

You can have a linear workflow with the array functions.

The following is unreadable:

$output = array_reduce(
  array_map(
    function($n) { return $n ** 2; }
    array_filter($input, function($n) { return $n % 2 == 0; })
 ),
function translateError(msg) {
var newErr = new Error(msg); // placed here to get correct stack
return e => {
newErr.originalError = e;
throw newErr;
}
}
async function asyncTask() {
const user = await UserModel.findById(1).catch(translateError('No user found'))
@staltz
staltz / music.md
Last active September 29, 2023 15:42
coding music

Not for everyone. Each programmer has their own appreciation of what is good coding music.

For when I need to think deep, debug something, or design

(From most influential to least)