Skip to content

Instantly share code, notes, and snippets.

Aram Kocharyan aramk

Block or report user

Report or block aramk

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@aramk
aramk / obj_memoize.coffee
Created Nov 7, 2014
Support for object arguments in _.memoize()
View obj_memoize.coffee
# Adds support for using object arguments with _.memoize().
nextMemoizeObjKey = 1
memoizeObjectArg = (func) ->
_.memoize func, (obj) ->
key = obj._memoizeObjKey
unless key?
key = obj._memoizeObjKey = nextMemoizeObjKey++
key
# Example:
@aramk
aramk / publish.sh
Last active May 9, 2017
Publishing Jekyll to gh-pages branch
View publish.sh
#!/bin/bash
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
cd $DIR
SELF=`basename $0`
SOURCE_BRANCH="master"
DEST_BRANCH="gh-pages"
TMP_DIR="tmp"
View curl_header.php
<?php
define('COOKIE_FILE', 'cookie.txt');
define('HEADER_REGEX', '#^.*?(\r?\n){2}#msi');
$ch = curl_init();
curl_setopt_array($ch, array(
CURLOPT_URL => $assetURL,
CURLOPT_POST => FALSE,
View DeferredQueueTest.js
require([
"dojo/Deferred"
// Add DeferredQueue and DeferredWrapper imports here
], function (Deferred, DeferredQueue, DeferredWrapper) {
var testDeferred = function () {
// Create a wrapper around a callback that returns a deferred object
return new DeferredWrapper(function () {
// Create a dummy deferred object to finish in 2 seconds
var df = new Deferred();
@aramk
aramk / DeferredWrapper.js
Created Feb 9, 2013
Wraps a function in a dojo.Deferred object.
View DeferredWrapper.js
define([
'dojo/_base/declare',
'dojo/_base/lang',
'dojo/Deferred'
], function (declare, lang, Deferred) {
return declare([Deferred], {
// summary:
// Wraps a function in a dojo.Deferred object.
@aramk
aramk / DeferredQueue.js
Created Feb 9, 2013
Resolves each dojo.Deferred in the queue sequentially, waiting for the previous to complete before moving on. Use this with DeferredWrapper: https://gist.github.com/aramkocharyan/4743839
View DeferredQueue.js
define([
'dojo/_base/declare',
'dojo/_base/lang',
'dojo/Deferred',
'utility/Log'
], function (declare, lang, Deferred, Log) {
// Internal ID for more useful logs
var queueID = 0;
@aramk
aramk / float-on-top.js
Last active Dec 12, 2015
Floats an element on the top of the screen when we scroll the page beyond it. This is useful for page headers for instance. The "overlap" CSS class is added and you can style it how you like. Something with position: fixed, top:0, left: 0 works well.
View float-on-top.js
(function ($) {
function getPositionInfo(elem) {
var pos = {};
pos.docViewTop = $(window).scrollTop();
pos.docViewBottom = pos.docViewTop + $(window).height();
pos.elemTop = $(elem).offset().top;
pos.elemBottom = pos.elemTop + $(elem).height();
return pos;
}
@aramk
aramk / ext-chart-theme-fix.js
Last active Dec 12, 2015
This is a redefinition of Ext.chart.theme to allow customisation of gradients for Ext JS.
View ext-chart-theme-fix.js
var NewThemeClass = function (config, base) {
// Arguments
config = Ext.apply({
gradientAngle: 45,
gradientDarkerRatio: 0.1
}, config);
var i = 0, l, colors, color,
seriesThemes, markerThemes,
@aramk
aramk / field_widget.php
Last active Dec 10, 2015
A Wordpress widget base class which reduces the amount of code needed to create a simple widget with fields. Allows overriding a method adding more complex fields. This code should be placed in your theme's function.php file. You can then subclass Field_Widget whenever you like by following the example given.
View field_widget.php
/**
* A Wordpress widget base class which reduces the amount of code needed to create a simple widget with fields. Allows overriding a method adding more complex fields.
*/
class Field_Widget extends WP_Widget {
private $fields = array();
private $defaults = array();
private $names = array();
function update($new_instance, $old_instance) {
@aramk
aramk / gist:4138482
Created Nov 24, 2012
Creates a link out a url string
View gist:4138482
String.prototype.linkify = function(target) {
target = typeof target != 'undefined' ? target : '';
return this.replace(/(http(s)?:\/\/(\S)+)/gmi, '<a href="$1" target="' + target + '">$1</a>');
};
"http://www.google.com".linkify() // "<a href="http://www.google.com" target="">http://www.google.com</a>"
You can’t perform that action at this time.