Skip to content

Instantly share code, notes, and snippets.

@carcinocron
carcinocron / Table.php
Created December 4, 2019 20:49
dump table in laravel phpunit or artisan tinker
<?php
namespace App\Console;
use Symfony\Component\Console\Helper\Table as SymfonyTable;
use Symfony\Component\Console\Output\StreamOutput;
class Table
{
static function dump ($headers, $rows = null) {
block china (huge exgress charges) https://serverfault.com/a/984766
```
PROJECT_ID="something"
gcloud compute --project=$PROJECT_ID firewall-rules create no-china-1 --description="Blocking these Chinese bots that want to rack up my network charges" --direction=INGRESS --priority=100 --network=default --action=DENY --rules=all --source-ranges=1.24.0.0/13,1.48.0.0/15,1.50.0.0/16,1.56.0.0/13,1.68.0.0/14,1.80.0.0/13,1.92.0.0/14,1.180.0.0/14,1.188.0.0/14,1.192.0.0/13,1.202.0.0/15,1.204.0.0/14,14.16.0.0/12,14.104.0.0/13,14.112.0.0/12,14.134.0.0/15,14.144.0.0/12,14.204.0.0/15,14.208.0.0/12,23.80.54.0/24,23.104.141.0/24,23.105.14.0/24,23.226.208.0/24,27.8.0.0/13,27.16.0.0/12,27.36.0.0/14,27.40.0.0/13,27.50.128.0/17,27.54.192.0/18,27.106.128.0/18,27.115.0.0/17,27.148.0.0/14,27.152.0.0/13,27.184.0.0/13,27.192.0.0/11,27.224.0.0/14,36.1.0.0/16,36.4.0.0/14,36.26.0.0/16,36.32.0.0/14,36.36.0.0/16,36.40.0.0/13,36.48.0.0/15,36.56.0.0/13,36.96.0.0/11,36.128.0.0/11,36.248.0.0/14,39.64.0.0/11,39.96.0.0/13,39.128.0.0/10,42.4.0.0/
@carcinocron
carcinocron / BindQueryLimit.js
Created July 8, 2019 15:31
Example of Vue.js Mixin to bind property from URL to component
export const defaultLimit = 25;
export default {
computed: {
limit: {
get() {
return parseLimit(this.$route.query.limit);
},
set(value) {
this.$router.push(

I checked the source code, union seems to be kind of hardcoded, in way that's not easy to use ->union(...)but substitute 'intersect' under the hood.

that said, you can manually do it long-form like this:

$q = DB::table('items')->where('id','>', 1)->union(DB::table('items')->where('id', '<', 5));
DB::select(str_replace('union', 'intersect', $q->toSql()), $q->getBindings());

or better:

$q1 = DB::table('items')-&gt;where('id','&gt;', 1);
@carcinocron
carcinocron / git_see_recently_updated_branches.sh
Last active April 2, 2021 18:01
git see recently updated branches
git for-each-ref --sort=committerdate refs/heads/ --format='%(HEAD) %(color:yellow)%(refname:short)%(color:reset) - %(color:red)%(objectname:short)%(color:reset) - %(contents:subject) - %(authorname) (%(color:green)%(committerdate:relative)%(color:reset))'
alias branches="git for-each-ref --sort=committerdate refs/heads/ --format='%(HEAD) %(color:yellow)%(refname:short)%(color:reset) - %(color:red)%(objectname:short)%(color:reset) - %(contents:subject) - %(authorname) (%(color:green)%(committerdate:relative)%(color:reset))'"
@carcinocron
carcinocron / ddcors.php
Created September 1, 2017 15:12
CORS usable dd (laravel)
header('Access-Control-Allow-Origin: *');
header('Access-Control-Allow-Methods: *');
header('Access-Control-Allow-Headers: *');
dd(__FILE__);
// or use a function
function ddcors(...$args) {
header('Access-Control-Allow-Origin: *');
header('Access-Control-Allow-Methods: *');
header('Access-Control-Allow-Headers: *');
@carcinocron
carcinocron / getTimezoneName.js
Last active April 2, 2021 18:02
getTimezoneName.js
function getTimezoneName() {
var timeSummer = new Date(Date.UTC(2005, 6, 30, 0, 0, 0, 0));
var summerOffset = -1 * timeSummer.getTimezoneOffset();
var timeWinter = new Date(Date.UTC(2005, 12, 30, 0, 0, 0, 0));
var winterOffset = -1 * timeWinter.getTimezoneOffset();
var timeZoneHiddenField;
if (-720 == summerOffset && -720 == winterOffset) { timeZoneHiddenField = 'Dateline Standard Time'; }
else if (-660 == summerOffset && -660 == winterOffset) { timeZoneHiddenField = 'UTC-11'; }
else if (-660 == summerOffset && -660 == winterOffset) { timeZoneHiddenField = 'Samoa Standard Time'; }
@carcinocron
carcinocron / 99-dev-machine.ini.md
Last active September 1, 2015 13:22
Increase Error Reporting in PHP for dev machines

increase error reporting in PHP (do not do this on production!!!!)

sudo nano /etc/php5/fpm/conf.d/99-dev-machine.ini

display_startup_errors=1

display_errors=1

<pre><?php
/**
The goal is fast + unique, this is not for cryptographically secure purposes!
*/
define('LOOP_COUNT',100000);
define()
$startTime = microtime(true);
@carcinocron
carcinocron / debugger pause beforeunload
Last active September 24, 2024 12:02
Chrome: pause before redirect
// Run this in the F12 javascript console in chrome
// if a redirect happens, the page will pause
// this helps because chrome's network tab's
// "preserve log" seems to technically preserve the log
// but you can't actually LOOK at it...
// also the "replay xhr" feature does not work after reload
// even if you "preserve log".
window.addEventListener("beforeunload", function() { debugger; }, false)