Skip to content

Instantly share code, notes, and snippets.

@mrded
mrded / javascript.js
Last active December 30, 2015 01:09
Hipster's code snippets.
// Call method.
var method = (success ? 'start' : 'stop');
obj[method]();
// Concatenation.
['first', 'name'].join(' '); // = 'first name';
['milk', 'coffee', 'suger'].join(', '); // = 'milk, coffee, suger'
// Value by default.
var name = myName || 'No name'; // Returns 'No name' when myName is null or undefined
@mrded
mrded / gist:7859414
Created December 8, 2013 15:57
Drupal: Views, render fields.
/**
* Implementation of template preprocess for the view.
*/
function template_preprocess_views_bootstrap_accordion_plugin_style(&$vars) {
$view = &$vars['view'];
$title_field = $vars['options']['title_field'];
// Get titles.
if (isset($view->field[$title_field])) {
foreach ($vars['view']->result as $key => $field) {
@mrded
mrded / .zshrc
Created January 22, 2014 23:32
my $PATH
# Customize to your needs...
GEMS=$(brew --prefix ruby)/bin
LOCALS=/usr/local/bin:/usr/local/sbin
SYSTEM=/usr/bin:/bin:/usr/sbin:/sbin
export PATH=$LOCALS:$GEMS:$PATH
@mrded
mrded / angularjs_search.js
Last active August 29, 2015 13:56
AngularJS: search
// Search.
var found = $filter('filter')($scope.suggestions, {uid: suggestion.uid}, true);
var found = $filter('getById')($scope.suggestions, fish_id);
// Find and delete.
$scope.suggestions.splice( $scope.suggestions.indexOf(suggestion), 1 );
// Get half of items.
$scope.suggestions.slice(0, $scope.suggestions.length / 2);
[{"id":1,"name":"AB InBev"},{"id":11,"name":"Adventure"},{"id":21,"name":"Barnet"},{"id":31,"name":"Beavertown"},{"id":41,"name":"Belleville"},{"id":51,"name":"Botanist"},{"id":61,"name":"Brew by Numbers"},{"id":71,"name":"Brew Wharf"},{"id":81,"name":"Brockley"},{"id":91,"name":"Brodie's"},{"id":101,"name":"Brüpond"},{"id":111,"name":"By the Horns"},{"id":121,"name":"Camden Town"},{"id":131,"name":"Clarence \u0026 Fredericks"},{"id":141,"name":"Crate"},{"id":151,"name":"The Cronx"},{"id":161,"name":"Earl's"},{"id":171,"name":"East London"},{"id":181,"name":"Ellenberg's"},{"id":191,"name":"Five Points"},{"id":201,"name":"Fuller's"},{"id":211,"name":"Hackney"},{"id":221,"name":"Ha'penny"},{"id":231,"name":"A Head in a Hat/Florence"},{"id":241,"name":"Hoppy Collie"},{"id":251,"name":"Howling Hops"},{"id":261,"name":"The Kernel"},{"id":271,"name":"The Lamb"},{"id":281,"name":"Late Knights"},{"id":291,"name":"Little Brew"},{"id":301,"name":"London"},{"id":311,"name":"London Fields"},{"id":321,"name":"Meantime"},{
@mrded
mrded / catch_error.js
Last active August 29, 2015 13:56
AngularJS: How to resolve promise objects.
function asynkFunction(){
return $timeout(function meAsynk(){
throw new Error('error in meAsynk');
}, 1);
}
asynkFunction().catch(function (err) {
errorHandler(err);
});
@mrded
mrded / install.sh
Created March 8, 2014 15:09
Sample Mobile Application (Angular.js, Cordova, Ionic, PhoneGap)
npm install -g cordova
npm install -g ionic
ionic start myApp
cd myApp
ionic platform ios
ionic emulate ios
ionic run ios
@mrded
mrded / array_object_bug.php
Last active August 29, 2015 13:59
PHP: ArrayObject bug
<?php
$obj = new ArrayObject();
$obj['hello'] = NULL;
print 'ArrayObject<br >';
var_dump(empty($obj['hello'])); // TRUE
var_dump(isset($obj['hello'])); // FALSE
var_dump(array_key_exists('hello', $obj)); // TRUE
class Test1 extends ArrayObject {
@mrded
mrded / example.module
Last active August 29, 2015 14:00
Drupal7: Update form element via AJAX.
<?php
function example_form($form, &$form_state) {
$form['foo'] = array(
'#type' => 'select',
'#title' => t('Foo'),
'#options' => array('one', 'two', 'three'),
'#ajax' => array(
'callback' => 'example_foo_callback',
'wrapper' => 'bar-sections'
@mrded
mrded / index.html
Created May 7, 2014 18:14
AngularJS: First item as active class
<ul class="nav nav-tabs">
<li ng-repeat="team in teams" ng-class="{active: $index == 0}">
<a href="#" data-toggle="tab">{{team.name}}</a>
</li>
</ul>