Skip to content

Instantly share code, notes, and snippets.

@Ocramius
Ocramius / find-missing-return-types.php
Last active September 5, 2018 10:27
Script to find classes/interfaces/traits with missing return types: ADD THEM TO YOUR SHIT.
<?php
require_once __DIR__ . '/vendor/autoload.php';
$namespace = 'PutYourProjectNamespaceHere\\';
foreach (new RegexIterator(new RecursiveIteratorIterator(new RecursiveDirectoryIterator(__DIR__ . '/src')), '/^.+\.php$/i', RecursiveRegexIterator::GET_MATCH) as $file) {
require_once $file[0];
}
@gaearon
gaearon / slim-redux.js
Last active April 25, 2024 18:19
Redux without the sanity checks in a single file. Don't use this, use normal Redux. :-)
function mapValues(obj, fn) {
return Object.keys(obj).reduce((result, key) => {
result[key] = fn(obj[key], key);
return result;
}, {});
}
function pick(obj, fn) {
return Object.keys(obj).reduce((result, key) => {
if (fn(obj[key])) {
@pygy
pygy / mithril.login_redirect.md
Last active March 23, 2019 16:51
Mithril Login redirect by Barney Carol

Taken from https://gitter.im/lhorie/mithril.js?at=553bdd1763c55be30636a16b in case it disappeared.

@barneycarol said:

[...] FWIW you can overcome a lot of apparent limitations in m.route by reinitialising m.route when things change

@tobscure said:

interesting, examples?

@barneycarol said:

Well I use it when authentication status changes

@stephenwf
stephenwf / Express.php
Last active August 30, 2016 14:55
Express.php
<?php
/** Requires classes from previous gist **/
/**
* Express lightweight wrapper around Server
*/
class Express extends Server implements ServerInterface {
/**
* Routing default registry
@stephenwf
stephenwf / Example.php
Last active August 29, 2015 14:15
Drupal OOP Hooks using reflection
<?php
/**
* Assumtions:
* IoC Container setup under $container
* EntityManager interface with 2 classes:
* - Traditional Storage
* - MongoDB
* 2 Services in IoC
* - services.user injects the Traditional Storage
var m = require('mithril');
var Navbar = require('./components/Navbar.js');
var Auth = require('./models/Auth.js');
var linksIn = [
{label:'calendar', href:'/calendar'},
{label:'logout', href:'/logout'}
];
@gilbert
gilbert / functions.js
Last active September 20, 2016 15:09
JavaScript Function Extensions
// Partially apply arguments to a function. Useful for binding
// specific data to an event handler.
// Example:
//
// var add = function (x,y) { return x + y }
// var add5 = add.papp(5)
// add5(7) //=> 12
//
Function.prototype.papp = function () {
var slice = Array.prototype.slice
@tracker1
tracker1 / 01-directory-structure.md
Last active April 26, 2024 21:26
Anatomy of a JavaScript/Node project.

Directory structure for JavaScript/Node Projects

While the following structure is not an absolute requirement or enforced by the tools, it is a recommendation based on what the JavaScript and in particular Node community at large have been following by convention.

Beyond a suggested structure, no tooling recommendations, or sub-module structure is outlined here.

Directories

  • lib/ is intended for code that can run as-is
  • src/ is intended for code that needs to be manipulated before it can be used
@Ocramius
Ocramius / pr.md
Created April 4, 2014 06:23 — forked from piscisaureus/pr.md

Locate the section for your github remote in the .git/config file. It looks like this:

[remote "origin"]
	fetch = +refs/heads/*:refs/remotes/origin/*
	url = git@github.com:joyent/node.git

Now add the line fetch = +refs/pull/*/head:refs/remotes/origin/pr/* to this section. Obviously, change the github url to match your project's URL. It ends up looking like this: