Skip to content

Instantly share code, notes, and snippets.

View aramk's full-sized avatar

Aram Kocharyan aramk

View GitHub Profile
@aramk
aramk / obj_memoize.coffee
Created November 7, 2014 11:50
Support for object arguments in _.memoize()
# 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 16:16
Publishing Jekyll to gh-pages branch
#!/bin/bash
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
cd $DIR
SELF=`basename $0`
SOURCE_BRANCH="master"
DEST_BRANCH="gh-pages"
TMP_DIR="tmp"
<?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,
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 February 9, 2013 04:27
Wraps a function in a dojo.Deferred object.
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 February 9, 2013 04:25
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
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 December 12, 2015 02:18
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.
(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 December 12, 2015 02:09
This is a redefinition of Ext.chart.theme to allow customisation of gradients for Ext 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 December 10, 2015 13:28
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.
/**
* 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 November 24, 2012 04:58
Creates a link out a url string
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>"