Skip to content

Instantly share code, notes, and snippets.

@hamakn
hamakn / codes.md
Created Mar 15, 2019
gRPC Code and HTTP Status Code
View codes.md
View V8JsNodeModuleLoader.php
<?php
require_once __DIR__.'/V8JsNodeModuleLoader_FileAccessInterface.php';
require_once __DIR__.'/V8JsNodeModuleLoader_NormalisePath.php';
/**
* Simple Node.js module loader for use with V8Js PHP extension
*
* This class understands Node.js' node_modules/ directory structure
* and can require modules/files from there.
*
@bgarrant
bgarrant / ValetSwitchPHP.md
Last active Jun 30, 2021
How to Switch PHP Version in Laravel Valet between PHP 7.1 and PHP 5.6
View ValetSwitchPHP.md

How to Switch PHP Version in Laravel Valet between PHP 7.1 and PHP 5.6

Valet switch PHP version with these commands

Install PHP 5.6 and switch Valet to PHP 5.6

valet stop
brew unlink php71
brew install php56
brew install php56-mcrypt
@derhansen
derhansen / removeJobsRedisDriver.php
Last active Jul 7, 2021
Laravel 5 - remove all jobs from a queue (redis driver)
View removeJobsRedisDriver.php
Redis::connection()->del('queues:myqueue');
@bradrydzewski
bradrydzewski / generate_docker_cert.sh
Last active Aug 12, 2021
Generate trusted CA certificates for running Docker with HTTPS
View generate_docker_cert.sh
#!/bin/bash
#
# Generates client and server certificates used to enable HTTPS
# remote authentication to a Docker daemon.
#
# See http://docs.docker.com/articles/https/
#
# To start the Docker Daemon:
#
# sudo docker -d \
@pauloricardomg
pauloricardomg / cors.nginxconf
Last active Aug 23, 2021
Nginx configuration for CORS-enabled HTTPS proxy with origin white-list defined by a simple regex
View cors.nginxconf
#
# Acts as a nginx HTTPS proxy server
# enabling CORS only to domains matched by regex
# /https?://.*\.mckinsey\.com(:[0-9]+)?)/
#
# Based on:
# * http://blog.themillhousegroup.com/2013/05/nginx-as-cors-enabled-https-proxy.html
# * http://enable-cors.org/server_nginx.html
#
server {
@odewahn
odewahn / error-handling-with-fetch.md
Last active Sep 9, 2021
Processing errors with Fetch API
View error-handling-with-fetch.md

I really liked @tjvantoll article Handling Failed HTTP Responses With fetch(). The one thing I found annoying with it, though, is that response.statusText always returns the generic error message associated with the error code. Most APIs, however, will generally return some kind of useful, more human friendly message in the body.

Here's a modification that will capture this message. The key is that rather than throwing an error, you just throw the response and then process it in the catch block to extract the message in the body:

fetch("/api/foo")
  .then( response => {
    if (!response.ok) { throw response }
    return response.json()  //we only get here if there is no error
  })
@brunogaspar
brunogaspar / macro.md
Last active Sep 25, 2021
Recursive Laravel Collection Macros
View macro.md

What?

If a nested array is passed into a Laravel Collection, by default these will be threaded as normal arrays.

However, that's not always the ideal case and it would be nice if we could have nested collections in a cleaner way.

This is where this macro comes in handy.

Setup

@gauravtiwari
gauravtiwari / window-auth-popup.es6.js
Last active Sep 27, 2021
Promise based popup window for server oAuth
View window-auth-popup.es6.js
/* global window */
const popup = (url) => {
const windowArea = {
width: Math.floor(window.outerWidth * 0.8),
height: Math.floor(window.outerHeight * 0.5),
};
if (windowArea.width < 1000) { windowArea.width = 1000; }
if (windowArea.height < 630) { windowArea.height = 630; }
@kalinchernev
kalinchernev / countries
Created Oct 6, 2014
Plain text list of countries
View countries
Afghanistan
Albania
Algeria
Andorra
Angola
Antigua & Deps
Argentina
Armenia
Australia
Austria