collected wisdom on REST API best practice.
- 200 : OK – Eyerything is working
- 201 : OK – New resource has been created
- 204 : OK – The resource was successfully deleted
- 304 : Not Modified – The client can use cached data
<?php | |
class StrCSV | |
public function strPutCsv($input, $delimiter = ',', $enclosure = '"') | |
{ | |
// Open a memory "file" for read/write... | |
$fp = fopen('php://memory', 'r+'); | |
// ... write the $input array to the "file" using fputcsv()... | |
fputcsv($fp, $input, $delimiter, $enclosure); | |
// ... rewind the "file" so we can read what we just wrote... | |
rewind($fp); |
// Avoid `console` errors in browsers that lack a console. | |
(function() { | |
var method; | |
var noop = function () {}; | |
var methods = [ | |
'assert', 'clear', 'count', 'debug', 'dir', 'dirxml', 'error', | |
'exception', 'group', 'groupCollapsed', 'groupEnd', 'info', 'log', | |
'markTimeline', 'profile', 'profileEnd', 'table', 'time', 'timeEnd', | |
'timeStamp', 'trace', 'warn' | |
]; |
<?php | |
// Do something more robust in production to check it's a valid post etc | |
// also use Monolog or similar to log, but hey this is an example :) | |
$logMessage = sprintf( | |
'JS_ERROR[%s] URL[%s] on file[%s:%s] UA[%s]', | |
$_POST['errorMessage'], | |
$_POST['url'], | |
$_POST['file'], | |
$_POST['lineNumber'], |
//*********** IMPORTS ***************** | |
var gulp = require('gulp'); | |
var sass = require('gulp-ruby-sass'); | |
var gutil = require('gulp-util'); | |
var rename = require("gulp-rename"); | |
var map = require("map-stream"); | |
var livereload = require("gulp-livereload"); | |
var concat = require("gulp-concat"); | |
var uglify = require('gulp-uglify'); | |
var watch = require('gulp-watch'); |
<?php | |
$function_filedate = new Twig_SimpleFunction( | |
'fileDate', | |
/** | |
* @param $file_path | |
* This function generates a new file path with the last date of filechange | |
* to support better better client caching via Expires header: | |
* i.e: |
<?php | |
/** | |
* dump args surrounded in html pre block and die | |
* | |
* @param mixed $args,... variable number of arguments | |
*/ | |
function dd() { | |
echo '<pre>'; | |
call_user_func_array('var_dump',func_get_args()); | |
echo '</pre>'; |
Encrypt Archive.zip saving as Archive.zip.dat, you'll be prompted to enter a password and confirm it
openssl enc -aes-256-cbc -in Archive.zip >Archive.zip.dat
Decrypt Archive.zip.dat saving as Archive.zip, you'll be prompted to enter the password you used to encrypt it
#!/usr/bin/env bash | |
TARGET_DIR=~/temp_dir git archive --format=tar HEAD | (cd $TARGET_DIR && tar xf -) |
<?php | |
function copy2clipboard($string){ | |
$descriptorspec = array( | |
0 => array("pipe", "r"), // stdin is a pipe that the child will read from | |
1 => array("pipe", "w"), // stdout is a pipe that the child will write to | |
2 => array("file", "a.txt", "a") // stderr is a file to write to | |
); | |
$process = proc_open('pbcopy', $descriptorspec, $pipes); | |
if (is_resource($process)) { | |
fwrite($pipes[0], $string); |