Skip to content

Instantly share code, notes, and snippets.

View gerardojbaez's full-sized avatar

Gerardo Baez gerardojbaez

View GitHub Profile
@lorisleiva
lorisleiva / toSqlWithBindings.php
Last active November 15, 2023 08:54
A little macro to get the SQL from a query builder without the annoying "?".
<?php
use Illuminate\Database\Eloquent\Builder;
Builder::macro('toSqlWithBindings', function () {
$bindings = array_map(
fn ($value) => is_numeric($value) ? $value : "'{$value}'",
$this->getBindings()
);
@mozillazg
mozillazg / supervisord.service
Last active December 1, 2023 12:59 — forked from tonyseek/supervisord.service
install and configure supervisord on centos 7.
[Unit]
Description=supervisord - Supervisor process control system for UNIX
Documentation=http://supervisord.org
After=network.target
[Service]
Type=forking
ExecStart=/bin/supervisord -c /etc/supervisord/supervisord.conf
ExecReload=/bin/supervisorctl reload
ExecStop=/bin/supervisorctl shutdown
@jrmadsen67
jrmadsen67 / gist:bd0f9ad0ef1ed6bb594e
Last active February 15, 2022 08:41
Laravel Quick Tip: Handling CsrfToken Expiration gracefully
Quick tip for handling CSRF Token Expiration - common issue is when you use csrf protection is that if
a form sits there for a while (like a login form, but any the same) the csrf token in the form will
expire & throw a strange error.
Handling it is simple, and is a good lesson for dealing with other types of errors in a custom manner.
In Middleware you will see a file VerifyCsrfToken.php and be tempted to handle things there. DON'T!
Instead, look at your app/Exceptions/Handler.php, at the render($request, Exception $e) function.
All of your exceptions go through here, unless you have excluded them in the $dontReport array at the
@tanksuzuki
tanksuzuki / supervisor.txt
Last active November 20, 2020 00:05
yum install supervisor
[root@a59c35ad939a /]# yum install epel-release
Loaded plugins: fastestmirror
Setting up Install Process
Loading mirror speeds from cached hostfile
* base: ftp.riken.jp
* extras: ftp.riken.jp
* rpmforge: ftp.riken.jp
* updates: ftp.riken.jp
Resolving Dependencies
--> Running transaction check
@frontendbeast
frontendbeast / Default (OSX).sublime-keymap
Last active July 16, 2019 07:45
Simple example of a key-mapped Sublime Text snippet (⌘+b for bold)
[
{ "keys": ["super+b"], "command": "insert_snippet", "args": {"name": "Packages/User/bold.sublime-snippet"} },
// Set context so shortcut works in HTML files only
{ "keys": ["super+b"], "command": "insert_snippet", "args": {"name": "Packages/User/bold.sublime-snippet"},"context":[{ "key": "selector", "operator": "equal", "operand": "text.html" }] }
]
@marcuslilja
marcuslilja / ubuntu-server-setup-16.04.md
Last active January 30, 2020 23:28
Server setup for Ubuntu 16.04 on Digital Ocean

Server setup for Ubuntu 16.04 on Digital Ocean

The setup installs the following software:

  • Nginx
  • MySQL
  • PHP
  • Node
  • Composer
@lesleh
lesleh / cache.js
Last active December 1, 2023 12:21
Basic memory cache implementation for JavaScript.
function Cache(config) {
config = config || {};
config.trim = config.trim || 600;
config.ttl = config.ttl || 3600;
var data = {};
var self = this;
var now = function() {
return new Date().getTime() / 1000;
@gibbs
gibbs / magento-country-codes
Created August 7, 2014 19:58
Magento Country Codes
AF - Afghanistan
AL - Albania
DZ - Algeria
AS - American Samoa
AD - Andorra
AO - Angola
AI - Anguilla
AQ - Antarctica
AG - Antigua and Barbuda
AR - Argentina
@lemiorhan
lemiorhan / post-receive
Last active February 8, 2023 10:06
Post-receive hook to deploy the code being pushed to production branch to a specific folder
#!/bin/bash
target_branch="production"
working_tree="PATH_TO_DEPLOY"
while read oldrev newrev refname
do
branch=$(git rev-parse --symbolic --abbrev-ref $refname)
if [ -n "$branch" ] && [ "$target_branch" == "$branch" ]; then
/*!
* Scroll Sneak
* http://mrcoles.com/scroll-sneak/
*
* Copyright 2010, Peter Coles
* Licensed under the MIT licenses.
* http://mrcoles.com/media/mit-license.txt
*
* Date: Mon Mar 8 10:00:00 2010 -0500
*/