Skip to content

Instantly share code, notes, and snippets.

@dancourse
dancourse / gist:8863879
Created February 7, 2014 14:44
Remove then re-add phonegap plugins with a grunt shell script
shell: {
restorePlugins :{
command: function ()
{
var toReturn = [];
var allPlugins = ["camera", "console", "device", "keyboard", "splashscreen", "statusbar", "file", "dialogs", "vibration"];
var preCommand = "org.apache.cordova.";
toReturn.push('echo "[calvium] Restoring plugins"');
@dancourse
dancourse / gist:45ad644fe6d4cc55c209
Created May 19, 2014 11:22
DalekJS: Custom `hasClass` method
// _addNewFunc is just a function that adds this to the main DalekJS test at run-time
_addNewFunc("hasClass", function (__selector, __needle)
{
// generate a random name for this element
var name = "hasClass-" + new Date().getTime(),
nameElem = "span#"+name;
return this.dse_self
.execute(function(__selector, __needle, __name)
@dancourse
dancourse / gist:df3e8ed330046fe6a7f6
Created October 9, 2014 08:18
Mixin for UnderscoreJs, checks if an object has anything for that value
// checks if the object has that value
_.mixin({
objHasValue: function (__obj, __key)
{
if(!_.isNull(__obj) && !_.isNull(__key) && !_.isNull(__obj[__key]) && !_.isUndefined(__obj[__key]))
{
return true;
}
return false;
}
@dancourse
dancourse / who-to-follow-item.html
Created October 15, 2014 09:27
Modular Controller structure for Backbone Marionette
<span>
<div class="profile-picture-wrapper">
<% if (profile.image && profile.image.file_resizable) { %>
<img src="<%= profile.image.file_resizable.replace('{resize_spec)', 'w_200,h_200,c_fill,g_face') %>" class="profile-panel__image img-responsive" />
<% } %>
</div>
<button class="btn btn-info js__follow-user pre-icon icon-user-plus btn-short"><span>Follow</span></button>
<h5 class="item-view__title js__clickThrough"><div class="username-wrapper"><%= username %></div></h5>
@dancourse
dancourse / gist:ce3b6bd07e509fc0e746
Created January 20, 2015 15:29
What should I pass back on a Custom Laravel Validation fail?
/**
* Check the user id is the Auth'd user id
*
* @param string $attribute
* @param mixed $value
* @return bool
*/
protected function validateUserIdIsAuthUserId( $attribute, $value )
{
if($value===Auth::user()->id)
@dancourse
dancourse / gist:50060765981ce204f292
Created February 4, 2015 09:33
Momentjs isAfter is always returning false "bug"
// Not quite the solution, but it works so I can move on!
// CHANGEME: a date to test against, change it to something you want
var dateToTest = moment('2015-02-04 08:00:00').valueOf();
// now
var now = moment().valueOf();
// use a "greater than" eval, rather than isAfter
var x = dateToTest > now;
@dancourse
dancourse / gist:8815977f247d7ebd962c
Created February 4, 2015 16:22
Is homestead's server time out of sync
# inside your homestead machine, ie. $homestead ssh
date
# Should give something like this, Wed Feb 4 16:21:30 UTC 2015
# That will tell you the time. If it's off by
# if it's bad, to fix it.
exit
# wait
homestead halt
@dancourse
dancourse / gist:7bc5d7aa230b5d01a727
Last active August 29, 2015 14:18
Laracasts/TestDummy : setting up lots of similar factories pattern
// Grade
$grade_defaults = [
'courseid' => 'factory:App\Models\Course',
'itemname' => $faker->sentence,
'itemtype' => $faker->word,
'score' => $faker->randomFloat(2, 0, 1),
'grademax' => 100
];
@dancourse
dancourse / gist:5ee17a596223c10d5648
Created April 2, 2015 10:18
Simple PHPunit provider example
class ScoringTest extends TestCase
{
/**
* Some Grades
*/
public static function all_grades_provider()
{
return [
[100.00],
[50.00],
@dancourse
dancourse / FeatureContext.php
Created July 14, 2015 12:27
Behat and Laravel simple solution to listen for Events
class FeatureContext extends MinkContext implements Context, SnippetAcceptingContext
{
/**
* @When I listen for the event :event
*/
public function iListenForTheEvent($event)
{
$redis = Redis::connection();
$redis->set('eventHeard', false);