Skip to content

Instantly share code, notes, and snippets.

@jimrubenstein
jimrubenstein / _git-objects-restore.php
Last active September 15, 2023 19:04
Restore files from .git/objects
#!/usr/local/bin/php
<?php
define('DIR', 'tree');
define('FILE', 'blob');
function main() {
$root_object = 'f3c8ec92f83e2a87c1d00a5681598126e23ab356';
restore_object($root_object, 'restored');
}
@jimrubenstein
jimrubenstein / ruleset.xml
Last active April 20, 2018 22:54
Custom PHP Code Sniffer ruleset, uses PSR2 as a base and uses tabs for indenting instead of spaces.
<?xml version="1.0"?>
<ruleset name="CustomCfg">
<description>
PSR2 style guide + tab indent instead of space.
</description>
<arg name="tab-width" value="4"/>
<rule ref="PSR2">
<exclude name="Generic.WhiteSpace.DisallowTabIndent" />
STRIPE_SECRET_KEY=XXXXXXX
STRIPE_PUBLIC_KEY=YYYYYYY
@jimrubenstein
jimrubenstein / An Example Controller.php
Created February 13, 2016 02:16
Extend/Manipulate the behavior of the Eloquent Query Builder to do custom things with your ORM-built queries
<?php namespace App\Http\Controllers\Party;
use App\Http\Controllers\Controller as BaseController;
use App\Party;
use Session;
use Redirect;
use Request;
use URL;
class Rsvp extends BaseController {
function getPageHistory() {
var hist = $.cookie('history');
try {
hist = JSON.parse(hist);
if (false == $.isArray(hist)) hist = [];
}
catch (e)
{
<div class="campaign-property-container">
<div class="campaign-property-value">
<? if ($Campaign->started()): ?>
<? if ($Campaign->running()): ?>
<span class="campaign-status mod-running">Running</span>
<? elseif ($Campaign->ended()): ?>
<span class="campaign-status mod-ended">Ended</span>
<? elseif ($Campaign->pending()): ?>
<span class="campaign-status mod-scheduled">Scheduled</span>
<? endif; ?>
<?php namespace App\Http\Middleware;
use Closure;
class NoCache {
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
$ php callable_test.php
bool(false)
bool(true)
<?php
class Test {
public function __invoke() {}
}
var_dump(is_callable('Test'));
@jimrubenstein
jimrubenstein / gist:e68e4011ebd4f4850762
Last active August 29, 2015 14:16
make a closure out of a callable
function closureify(callable $fn)
{
return function() use ($fn) {
return call_user_func_array($fn, func_get_args());
};
}
$ mysql -e 'show slave status \G' -u root | grep "Running: No"
$ echo $?
1
$ mysql -e 'show slave status \G' -u root | grep "Running"
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
$ echo $?
0