Skip to content

Instantly share code, notes, and snippets.

@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);
});
[{"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 / 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);
@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 / 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 / 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 / foo.rb
Created November 20, 2013 21:09
Ruby: Get array of prime numbers.
(1..100).select {|x| (1..x).select{|y|x%y==0}.size==2 }
=> [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97]
@mrded
mrded / custom_index.php
Created November 20, 2013 17:01
Drupal: Add custom field to Search API Solr index
<?php
/**
* Implements hook_entity_property_info_alter().
*/
function example_search_api_property_entity_property_info_alter(&$info) {
$info['node']['properties']['created_week_day'] = array(
'type' => 'text',
'label' => t('Week day of node creation'),
'sanitized' => TRUE,
'getter callback' => 'example_search_api_property_weekday_getter_callback',
@mrded
mrded / boost_solr.php
Created November 15, 2013 15:46
Drupal: boost relevance for solr search. #1926090
<?php
/**
* Implements hook_search_api_solr_query_alter().
*/
function custom_api_search_api_solr_query_alter(array &$call_args, SearchApiQueryInterface &$query) {
$call_args['params']['fl'] = 'is_votes-sightsrank,' . $call_args['params']['fl'] ;
$call_args['params']['bf'] = "recip(rord(is_votes-sightsrank),1, 1000, 1000)";
}
@mrded
mrded / foo.module
Created November 11, 2013 19:22
Drupal 8: Working with variables.
<?php
\Drupal::config('module_name.settings')->set('variable', 'hello');
$variable = \Drupal::config('module_name.settings')->get('variable');