Skip to content

Instantly share code, notes, and snippets.

@sergiors
sergiors / _functions.php
Last active April 17, 2017 05:52
Reduce seu novo melhor amigo (Exemplos PHP)
<?php
function every($fn, $ls)
{
$keys = array_keys($ls);
$params = (new \ReflectionFunction($fn))->getParameters();
return array_reduce($keys, function ($carry, $idx) use ($fn, $ls, $params) {
$args = $ls[$idx];
@m-coding
m-coding / regex-yyyy-mm-dd.js
Last active November 14, 2024 08:49
javascript regex to match date pattern YYYY-MM-DD
// allows YYYY/M/D and periods instead of slashes
// http://stackoverflow.com/questions/24989065/trying-to-validate-yyyy-mm-dd
/^\d{4}[\/.]\d{1,2}[\/.]\d{1,2}$/
// YYYY-MM-DD and YYYY-M-D
// http://stackoverflow.com/questions/6177975/how-to-validate-date-with-format-mm-dd-yyyy-in-javascript
/^\d{4}\-\d{1,2}\-\d{1,2}$/
// YYYY-MM-DD
// https://gist.github.com/arth2o/8471150

Promises vs Eventual Values

A few times on Twitter, I've complained that Promises are a poor conceptual stand-in for Eventual Values.

A colleague of mine pointed out that I tweet this or something like it every few months. He's correct, I do.

The responses usually flow in saying something to the effect of "Well,

@andrewahead4
andrewahead4 / rest_insert_post.php
Last active August 6, 2024 08:59
A simple post insert using WP REST API and PHP over basic authentication
<?php
///////////////////////////////////////////////////////////////////////////////////
// //
// This is using a sample local WordPress Install and is not production safe //
// It uses the REST and Basic Auth plugins //
// //
///////////////////////////////////////////////////////////////////////////////////
@Delerina
Delerina / Haskell - infix to postfix
Created July 12, 2015 19:13
This haskell program takes an expression from the user in infix, converts it to postfix, and evaluates it.
{-
This program takes an expression from the user in infix,
converts it to postfix, and evaluates it.
Written in Haskell
By Delerina Hill
Compiled and run using WinGHCi
-}
-- | Main entry point to the application.
module Main where
configure.bat -opensource -confirm-license -release -static -system-zlib -system-libpng -system-libjpeg -no-accessibility -no-opengl -no-sql-ibase -no-sql-mysql -no-sql-oci -no-sql-tds -no-sql-db2 -no-sql-odbc -no-sql-psql -no-sql-sqlite -no-sql-sqlite2 -no-qml-debug -no-dbus -nomake examples -nomake tools -nomake tests -D QT_NO_GRAPHICSVIEW -D QT_NO_GRAPHICSEFFECT -D QT_NO_STYLESHEET -D QT_NO_STYLE_CDE -D QT_NO_STYLE_CLEANLOOKS -D QT_NO_STYLE_MOTIF -D QT_NO_STYLE_PLASTIQUE -D QT_NO_PRINTPREVIEWDIALOG -mp -icu -no-angle -openssl-linked -I C:\Richard\wkhtmltopdf\static-build\msvc2013-win32\deplibs\include -L C:\Richard\wkhtmltopdf\static-build\msvc2013-win32\deplibs\lib OPENSSL_LIBS="-LC:\\Richard\\wkhtmltopdf\\static-build\\msvc2013-win32\\deplibs\\lib -lssleay32 -llibeay32 -lUser32 -lAdvapi32 -lGdi32 -lCrypt32"
@neel-krishnaswami
neel-krishnaswami / abt
Last active June 15, 2021 21:17
Abstract binding trees implementation
(* -*- mode: ocaml; -*- *)
module type FUNCTOR = sig
type 'a t
val map : ('a -> 'b) -> 'a t -> 'b t
end
type 'a monoid = {unit : 'a ; join : 'a -> 'a -> 'a}
type var = string
@dkemper
dkemper / Application\Service\MemcachedStorageFactory.php
Last active January 27, 2021 18:59
Zend Framework 2 - Session Memcached Configuration with Failover
<?php
namespace Application\Service;
use Zend\Cache\Storage\Adapter\MemcachedOptions;
use Zend\Cache\Storage\Adapter\MemcachedResourceManager;
use Zend\Cache\StorageFactory;
use Zend\ServiceManager\FactoryInterface;
use Zend\ServiceManager\ServiceLocatorInterface;
use Zend\Session\SaveHandler\Cache;
@grizzm0
grizzm0 / Foo.php
Last active August 9, 2021 14:13
Best practice form/input-filter setup for ZF3
<?php
namespace Application\Entity;
/**
* Class Foo
*
* @package Application\Entity
*/
class Foo
{
@twn39
twn39 / promise.js
Created October 24, 2014 07:34
Promise [bluebird]
var Promise = require('bluebird');
var fs = require('fs');
function readFile(path) {
var file = new Promise(function(resolve, reject) {
fs.readFile(path, 'utf8', function(err, data) {
if(err) {
reject(err);
} else {