Skip to content

Instantly share code, notes, and snippets.

View gms8994's full-sized avatar

Glen Solsberry gms8994

View GitHub Profile
@gms8994
gms8994 / AppServiceProvider.php
Created November 4, 2019 19:59
Query builder macro to replace one where clause with another
/**
* Replaces a where clause in a Builder with another where clause
*/
Builder::macro('replaceWhere', function (Builder $passedQuery, \Closure $howToGetValue) {
$wheres = $passedQuery->wheres;
$query = $passedQuery->cloneWithout([ 'wheres' ]);
$bindings = [];
foreach ($wheres as &$where) {
### Keybase proof
I hereby claim:
* I am gms8994 on github.
* I am gms (https://keybase.io/gms) on keybase.
* I have a public key ASCHChhicXQkZY3KFtFaXdqMoc-UBiTI3ptvPW5QYZ9r8Qo
To claim this, I am signing this object:
### Keybase proof
I hereby claim:
* I am gms8994 on github.
* I am gms (https://keybase.io/gms) on keybase.
* I have a public key ASCrMIBpO1U0IJmhCiiL_h2IJ_nJNFIo52aVp0Q-J0DX-wo
To claim this, I am signing this object:
public function instantiate($class) {
$model = Yii::$app->modelMapper->instantiateObject(strtolower($class));
if (is_null($model)) {
$entityConfigId = substr($this->type, strlen("entity_"));
$entityConfig = \epmx\frontend\common\models\EntityConfig::findOne(['id' => $entityConfigId]);
$model = new \epmx\frontend\common\models\Entity(['entityConfig' => $entityConfig]);
}
return $model;
}
$_vendorModel = $this->instantiate('Vendor')->find()->where(['name' => $vendorModel->name])->one();
if (is_null($_vendorModel)) {
$_vendorModel = $this->instantiate('Vendor');
$_vendorModel->name = $vendorModel->name;
$success = $_vendorModel->save();
$dirtyAttributes = $itemVendorModel->dirtyAttributes;
$dirtyAttributes = array_filter($dirtyAttributes, function($v) { return $v !== ""; });
if (! $success
@gms8994
gms8994 / app-Http-Controllers-MainController.php
Last active August 29, 2015 14:25
Argument 1 passed to App\Http\Controllers\MainController::search() must be an instance of Illuminate\Http\Request, instance of Symfony\Component\HttpFoundation\Request given
<?php
namespace App\Http\Controllers;
use App\Models\Program;
use Illuminate\Http\Request;
use Illuminate\Http\Response;
class MainController extends Controller {
@gms8994
gms8994 / speedtest-report.pl
Created June 25, 2015 13:40
Automated speedtest. Needs speedtest-cli installed.
#!/usr/bin/perl
use Data::Dumper;
use DBI;
my $dbh = DBI->connect("", "", "", { AutoCommit => 1 });
my $data = `/usr/local/bin/speedtest-cli --simple`;
my @lines = split /\n/, $data;
@gms8994
gms8994 / hey.rb
Last active August 29, 2015 14:23 — forked from quad/hey.rb
#!/usr/bin/env ruby
#
# hey! a minimalist CRM for http://todotxt.com/
#
# hey tells you one thing you should do regularly, but haven't done lately.
#
# $ todo.sh lf hey
# 1 @phone Mom (+1 234 567 8901) +family
# 2 @skype Dad +family
# 3 @email mentor
namespace :deploy do
desc 'Restart application'
task :restart do
on roles(:web) do
execute "curl -qX POST -H 'authorization: abcd1234' http://www.example.com/_token"
end
end
task :migrate_install do
@gms8994
gms8994 / gist:10548482
Created April 12, 2014 18:00
keybase.md
### Keybase proof
I hereby claim:
* I am gms8994 on github.
* I am gms (https://keybase.io/gms) on keybase.
* I have a public key whose fingerprint is 304F CBA9 8265 50E1 2FF7 5B07 A90A F690 B812 799C
To claim this, I am signing this object: