Github: How to revert multiple commits

If you haven’t generated dependencies for other collaborators with your code and you wish to back up several commits, this should work just fine: $ git reset –hard HEAD is now at xxxxxxx Description $ git push -f Total 0 (delta 0), reused 0 (delta 0) To https://github.com/username/repository.git + 725b5eba…12739094 master -> master (forced update)

Read More

Tip on Passing Variable to Raw Custom Grid View Row

Here’s a handy tip on how to pass variables to the custom code in Gridview for raw formatted rows. I’m embarrassed that I’d never seen this before. I’d never the used the syntax and never previously been able to find out how to do this. The key part is “function ($model) use ($custom_variable) {}” where […]

Read More

Yii2 Active Record Hidden Active Form Field or How to Hide an Active Form Field

Here’s a small tip on how to create a hidden field in an active record form, within the model: <?php $form = ActiveForm::begin(); ?> <?= $form->field($model, ‘fullname’)->textInput([‘maxlength’ => true]) ?> /* Example of hiddenInput for an ActiveRecord Active $form->field */ <?= $form->field($model, ‘state’)->hiddenInput([‘value’=> $src->state])->label(false);?> <?= $form->field($model, ‘position_str’)->textInput([‘maxlength’ => true]) ?> <?php ActiveForm::end(); ?>

Read More

Build comma separated string with conjunction

Here’s a comma separated string function which uses the serial comma properly with a conjunction in a list. e.g. apple, berry, ice cream => apple, berry and ice cream. It’s essentially a natural language join: public static function natural_language_join(array $list, $conjunction = ‘and’) { $last = array_pop($list); if ($list) { return implode(‘, ‘, $list) . […]

Read More

Yii2 Gridview Filtering with Tabs

If you’re using Yii2 Gridview with tabs and notice that when the user filters the results, posting the page goes to the wrong tab. This solution worked great for me: $(document).ready(function() { $(‘a[data-toggle=\”tab\”]’).on(‘show.bs.tab’, function (e) { localStorage.setItem(‘lastTab’, $(this).attr(‘href’)); }); var lastTab = localStorage.getItem(‘lastTab’); if (lastTab) { $(‘[href=\”‘ + lastTab + ‘\”]’).tab(‘show’); } }); via Maintain […]

Read More

Viewing the Native SQL Generated by Yii Queries

Here’s how to see the native SQL or raw SQL generated by Yii queries. The easy way is to open the debug area and click on the DB tab. Recently, I was debugging complex SQL queries for background tasks and wanted to see the raw SQL generated. The debugger isn’t as easily available. I used […]

Read More

Search and Replace in Atom for Unused Language Strings

If you need to perform a Regex search for unused language strings or use replace to activate them again in Atom, there’s a fairly easy way to do this. You will need to turn on Regex search in the find dialog by clicking the .* button: For search, I used (.+) to find strings in between […]

Read More

Bootstrap Social Icons CSS

I also very much liked Social Buttons for Bootstrap. You just include their CSS and they show you how to create icons and buttons: <a class=”btn btn-block btn-social btn-twitter”> <span class=”fa fa-twitter”></span> Sign in with Twitter </a>

Read More

What’s the current UNIX timestamp?

Need to know the current UNIX timestamp? I think my new favorite helper site is currenttimestamp.com. I was writing a ton of time sensitive code for background jobs and it helped to know the current UNIX time for testing. Here’s what the site offers:

Read More