Skip to content

Instantly share code, notes, and snippets.

View gms8994's full-sized avatar

Glen Solsberry gms8994

View GitHub Profile
@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 / 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
#!/usr/bin/perl
use strict;
use warnings;
use Data::Dumper;
use HTML::Entities;
use iCal::Parser;
use LWP::UserAgent::Cached;
use Text::Table;
@gms8994
gms8994 / Laravel Select with data- Attributes
Created September 26, 2013 21:21
Laravel Select with data- Attributes
Form::macro('selectWithAttribs', function($name, $options, $default = null) {
$opt = array();
$select = '<select name="' . $name . '">';
foreach ($options as $option) {
$opt_node = '<option value="' . $option->value . '"';
$props = $option->getAttributes();
unset($props['value'], $props['key']);
my $css = CSS->new({ 'parser' => 'CSS::Parse::Heavy', 'adaptor' => 'CSS::Adaptor::Debug' });
$css->read_file($css_file);
die $css->output();
#!/usr/bin/perl
use warnings;
use strict;
use CSS;
my $css = CSS->new({ 'parser' => 'CSS::Parse::Heavy', 'adaptor' => 'CSS::Adaptor::Debug' });
$css->read_file('bootstrap.css');
die $css->output();