The popular open-source contract for web professionals by Stuff & Nonsense
- Originally published: 23rd December 2008
- Revised date: March 15th 2016
- Original post
<?php | |
/** | |
* ProcessWire (2.5) InputfieldFile front-end upload form example | |
* Various workarounds to get it working with Errors for WireUpload | |
* and removing files upload after error | |
*/ | |
$sent = false; | |
$upload_path = $config->uploadTmpDir; |
function groupBy(list, props) { | |
return list.reduce((a, b) => { | |
(a[b[props]] = a[b[props]] || []).push(b); | |
return a; | |
}, {}); | |
} | |
// Usage. | |
groupBy([{ | |
id: 1, |
declare global { | |
interface Array<T> { | |
groupBy(prop: T): Array<T>; | |
} | |
} | |
if (!Array.prototype.groupBy) { | |
Array.prototype.groupBy = (prop: string) => { | |
return this.reduce(function(groups, item) { | |
const val = item[prop]; |
This script is intended to automatically fix the sequence numbers for all tables in the current database.
This is accomplished through the use of the setval()
command, which we provide with the next ID value we wish to make use of.
We use the setval(sequence, number, is_called)
overload
and set is_called = false
in conjunction with COALESCE(MAX + 1, 1)
to ensure that, with an empty table, the next sequence
value is 1
as expected.
import λ from "apex.js"; | |
import { Pool } from "pg"; | |
// connection details inherited from environment | |
const pool = new Pool({ | |
max: 1, | |
min: 0, | |
idleTimeoutMillis: 120000, | |
connectionTimeoutMillis: 10000 | |
}); |
<?php | |
/** | |
* Grab the url of a publicly embeddable video hosted on vimeo | |
* @param str $video_url The "embed" url of a video | |
* @return str The url of the thumbnail, or false if there's an error | |
*/ | |
function grab_vimeo_thumbnail($vimeo_url){ | |
if( !$vimeo_url ) return false; | |
$data = json_decode( file_get_contents( 'http://vimeo.com/api/oembed.json?url=' . $vimeo_url ) ); |