Skip to content

Instantly share code, notes, and snippets.

View safareli's full-sized avatar

Irakli Safareli safareli

View GitHub Profile
var each = function(callback){
return function(array){
for(var i = 0;i < array.length; i++){
var arg = [].slice.call(arguments);
arg[0] = array[i];
callback.apply(this,arg);
}
};
};
@safareli
safareli / storer.js
Last active August 29, 2015 14:02
in memory data store
function storer(key, val) {
if (arguments.length === 1)
return this[key];
else if (arguments.length === 0)
return this;
if (typeof val === "function")
return function () {
return val.apply(storer.bind(this, key), arguments);
}.bind(this);
setTimeout(console.log.bind(console, this), 1);
function arrayToFuncs() {
var functions = arguments;
return function (args) {
return [].map.call(functions, function (func, i) {
if (func == null)return args[i];
return func.call(undefined, args[i]);
});
}
}
@safareli
safareli / memoize.js
Last active August 29, 2015 14:05
memorize recursive function results
/*
// implementation 1
function memoize(func){
var store = {};
return function recursive(a){
if(store[a] == null) {
store[a] = func(recursive,a);
}
return store[a];
};
@safareli
safareli / profile_page.php
Created August 11, 2014 12:39
make possable to use <profile> inside block's pages field
<?php
/**
* Implements hook_module_implements_alter().
*/
function MODULE_NAME_module_implements_alter(&$implementations, $hook) {
if ($hook == 'block_list_alter') {
// We need our module to run hook_block_list_alter() first.
$module = 'MODULE_NAME';
// Pull out our own hook implementation details.
$group = array($module => $implementations[$module]);
@safareli
safareli / Drupal Web Services
Last active August 29, 2015 14:06
სასარგებლო ლინკები RESTfull ვებ სერვისებზე Drupal-ის ჭრილში
Drupal Web Services
@safareli
safareli / args2obj.js
Last active August 29, 2015 14:06
create function to create object from arguments
function args2Obj () {
var keys = Array.prototype.slice.apply(arguments);
return function () {
var values = Array.prototype.slice.apply(arguments);
return keys.reduce(function (result,key,index) {
result[key] = values[index];
return result;
},{});
};
};
@safareli
safareli / load_field_values.php
Last active August 29, 2015 14:07
load only field values instead of whole node
//from : http://drupal.stackexchange.com/questions/30904/retrieve-a-field-value-without-loading-the-entire-node
function load_field_values($field_name, $entity_type, $bundle, $nids) {
$query = db_select("field_revision_{$field_name}", 'f')
->fields('f', array('entity_id', "{$field_name}_value"))
->condition('entity_type', $entity_type);
if ($bundle)
$query->condition('bundle', $bundle);
$query
->condition('entity_id', $nids, 'IN')
@safareli
safareli / iOS_LIBs.md
Last active August 29, 2015 14:07
iOS გამოსადექი ბიბლიოთეკები და რესურსები
#import <UIKit/UIKit.h>
@interface UILabel (AutoResizeingFix)
@end