Skip to content

Instantly share code, notes, and snippets.

### Keybase proof
I hereby claim:
* I am kojilab on github.
* I am omoratin (https://keybase.io/omoratin) on keybase.
* I have a public key ASBdcT5P4lJ3o-QdBX4PAYoPUNOpANXaLdgAKXBql5Wi7Qo
To claim this, I am signing this object:
Array.prototype.flatten = function() {
return this.reduce(function(acc, v) {
if (!Array.isArray(v)) {
acc.push(v)
} else {
acc = acc.concat(v.flatten())
}
return acc;
}, [])
@kojilab
kojilab / gist:5dc14501809936a45a8d
Created February 29, 2016 22:09
jQuery Plugin to highlight occurrences of a word
$.fn.showKeywords = function(kwds) {
kws = kwds || [];
if (!$.isArray(kwds) || kwds.length === 0) return this;
var str = $.trim(kwds.join('|'));
if (str.length === 0) return this;
var regex = new RegExp('\\b('+str+')\\b', 'gim');
this.each(function() {
var children = $(this).children();
@kojilab
kojilab / gist:c2c7e4e67063ead5dc37
Last active August 29, 2015 14:13
Phalcon - Quick way to expose Mongo collection as a Rest API
<?php
use Phalcon\DI\FactoryDefault,
Phalcon\Mvc\Micro,
Phalcon\Config\Adapter\Ini as IniConfig,
Phalcon\Mvc\Micro\Collection as MicroCollection;
$di = new FactoryDefault();
$di->set('url', function(){
$url = new Phalcon\Mvc\Url();
$url->setBaseUri('/');
@kojilab
kojilab / Tooltipster Tweaks
Last active December 15, 2015 21:18
Tooltipster Mods to handle content as a jquery object and not a string. And content option as a function
/*
Tooltipster 2.1 | 2/12/13
A rockin' custom tooltip jQuery plugin
Developed by: Caleb Jacob - calebjacob.com
Copyright (C) 2013 Caleb Jacob
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@kojilab
kojilab / Sails scaffold policy to add user ID to model
Created March 15, 2013 14:30
Sails's scaffold API is pretty sweet. However one may want to hide the User ID in the API. To do this, you can use a policy file to tie the model's user ID to the user ID in your session. Here's an example. Get Sails at https://github.com/balderdashy/sails
module.exports = function (req,res,ok) {
var requiresUserId = false;
// not all records may need the user ID so let's see what entity we're dealing with in the call
switch(req.params.entity) {
case 'project':
case 'task':
requiresUserId = true;
break;
}