Here's how you could create custom error classes in Node.js using latest ES6 / ES2015 syntax.
I've tried to make it as lean and unobtrusive as possible.
errors/AppError.js
| // Implementation in ES6 | |
| function pagination(c, m) { | |
| var current = c, | |
| last = m, | |
| delta = 2, | |
| left = current - delta, | |
| right = current + delta + 1, | |
| range = [], | |
| rangeWithDots = [], | |
| l; |
| <?php namespace App\Providers; | |
| use Illuminate\Support\ServiceProvider; | |
| /** | |
| * If the incoming request is an OPTIONS request | |
| * we will register a handler for the requested route | |
| */ | |
| class CatchAllOptionsRequestsProvider extends ServiceProvider { |
| var elements = document.querySelectorAll("div"), | |
| callback = (el) => { console.log(el); }; | |
| // Spread operator | |
| [...elements].forEach(callback); | |
| // Array.from() | |
| Array.from(elements).forEach(callback); | |
| // for...of statement |
| <?php | |
| use RecursiveDirectoryIterator; | |
| use RecursiveIteratorIterator; | |
| use SplFileInfo; | |
| # http://stackoverflow.com/a/3352564/283851 | |
| /** | |
| * Recursively delete a directory and all of it's contents - e.g.the equivalent of `rm -r` on the command-line. |
<?php
/**
* Bootstrap auto clearfix from inside loops.
* Put this function at the start of the loop before other bootstrap cols are called.
*
* @param int $i The count from within the loop where the function is called. Starting with 0.
* @param array $args ['xs'=> 12, 'sm' => 6, 'md' => 4, 'lg' => 3]I've been using a lot of Ansible lately and while almost everything has been great, finding a clean way to implement ansible-vault wasn't immediately apparent.
What I decided on was the following: put your secret information into a vars file, reference that vars file from your task, and encrypt the whole vars file using ansible-vault encrypt.
Let's use an example: You're writing an Ansible role and want to encrypt the spoiler for the movie Aliens.
| $file = 'http://www.example.com/path/to/file.ext'; | |
| $headers = array_change_key_case(get_headers($file, TRUE)); | |
| $filesize = $headers['content-length'][1]; | |
| if ( $headers[0] != 'HTTP/1.1 404 Not Found' ) { | |
| header('Content-Description: File Transfer'); | |
| header('Content-Type: application/octet-stream'); | |
| header('Content-Disposition: attachment; filename='.basename($file)); |
#launchd Usage
I have a bash script called foo.sh that takes one command line argument, bar. I want it to run every 60 seconds and load at startup.
plist is Apple Property Listcom.mydomain.foo.plist Name of launchd plist file should be a reverse fqdn, like (this may not be required, but convention)com.mydomain.foo.plist lives in $HOME/Library/LaunchAgents and is ran as that user.com.mydomain.foo.plist can also live /Library/LaunchDaemons or /Library/LaunchAgents, have requirements, ran as rootplist with launchctl load com.mydomain.foo.plistplist with lauchctl unload com.mydomain.foo.plist| location ~* ^/remote-files/(http[s]*://)(.*?)/(.*) { | |
| # Do not allow people to mess with this location directly | |
| # Only internal redirects are allowed | |
| internal; | |
| # nginx has to be able to resolve the remote URLs | |
| resolver 8.8.8.8; | |
| # Location-specific logging | |
| #access_log /usr/local/etc/nginx/logs/internal_redirect.access.log main; |