Skip to content

Instantly share code, notes, and snippets.

View dmikey's full-sized avatar
🕶️
Thug Life

Derek Anderson dmikey

🕶️
Thug Life
View GitHub Profile
@dmikey
dmikey / gist:6800380
Created October 2, 2013 20:53
Simple jquery template usage $(element for display).($template as jquery selector, data);
$.fn.tmpl = function(template, data){
var _ = {
cache: {},
// John Resig - simple html template
render: function render(template, data) {
// Figure out if we're getting a template, or if we need to
// load the template - and be sure to cache the result.
var fn = !/\W/.test(template) ?
_.cache[template] = _.cache[template] ||
render(document.getElementById(template).innerHTML) :
@dmikey
dmikey / litecoin genesis block
Created January 10, 2014 18:36
create litecoin genesis block, the missing code
assert(block.hashMerkleRoot == uint256("0x38ca78a781d3c571a681ea2241ffb1e0d89bd1ecd3499f1bf6edeaa8751e7151"));
// If genesis block hash does not match, then generate new genesis hash.
if (false && block.GetHash() != hashGenesisBlock)
{
printf("Searching for genesis block...\n");
// This will figure out a valid hash and Nonce if you're
// creating a different genesis block:
uint256 hashTarget = CBigNum().SetCompact(block.nBits).getuint256();
uint256 thash;
<script src="//cdnjs.cloudflare.com/ajax/libs/jquery/2.0.3/jquery.min.js">
<script src="//cdnjs.cloudflare.com/ajax/libs/underscore.js/1.6.0/underscore-min.js">
<script>
(function (global, jQuery, underscore) {
global._$ = global._$ || function(){
Object.getOwnPropertyNames(underscore).forEach(function(property) {
if(typeof underscore[property] == 'function'){
(function(){
jQuery[property] = function(){
return underscore[property].apply(0, arguments);
@dmikey
dmikey / WrappedLeftRightArranger
Last active August 29, 2015 13:58
Extend enyo layout LeftRightArranger, offers better support for wrapped panels (works on non wrapped panels as well), esp handy in rotators/heros.
enyo.kind({
name: "WrappedLeftRightArranger",
kind: "LeftRightArranger",
start: enyo.inherit(function(sup) {
return function() {
sup.apply(this, arguments);
var s = this.container.fromIndex;
var f = this.container.toIndex;
var c$ = this.getOrderedControls(f);
var o = Math.floor(c$.length/2);
@dmikey
dmikey / b3.Style.js
Last active August 29, 2015 14:01
Enyo Style Kind
enyo.kind({
name: "b3.Style",
tag: "style",
styles:[],
create: function(){
//create style strings from each inner components style objects
enyo.forEach(this.components, function(style){
var innerStyles = [];
for (var property in style.style) {
if (style.style.hasOwnProperty(property)) {
@dmikey
dmikey / enyo.media.audio.backport.js
Created July 15, 2014 21:46
enyo.Media and enyo.Audio, backport to Enyo 2.2
(function (enyo, scope) {
/**
* Fires when element stops fetching [media]{@link enyo.Media} data before it is
* completely downloaded, but not due to an error.
*
* @event enyo.Media#event:onAbort
* @type {Object}
* @property {Object} sender - The [component]{@link enyo.Component} that most recently
* propagated the [event]{@link external:event}.
* @property {Object} event - An [object]{@link external:Object} containing
@dmikey
dmikey / enyo.Once.js
Last active August 29, 2015 14:04
Gives Enyo the ability to generate functions that can only be executed ONE time, regardless of how many times it is called.
(function(enyo, scope){
/**
* _enyo.Once_ returns a function that will only be executed one time no matter
* how many times it was called.
*
* borrowed from underscore
*
* @class enyo.Once
* @public
@dmikey
dmikey / enyo.ShareThis.js
Created July 17, 2014 21:43
Enyo control, that displays a ShareThis button. Requires use of enyo.Once (https://gist.github.com/dmikey/600ebf57cc11e085d13c) , see it in action: http://jsfiddle.net/toxigenicpoem/YE2LJ/show
(function(enyo, scope){
//load share this on the page
var loadShareThis = enyo.Once(function(callback) {
enyo.load('//w.sharethis.com/button/buttons.js',
callback
);
});
var checkShareThis = function(callback) {
function merge(target, src) {
//quickly merge all values from
//retrieved data into the store
Object.keys(src).forEach(function (key) {
if (typeof src[key] !== 'object' || !src[key]) {
target[key] = src[key];
} else {
if (!target[key]) {
target[key] = src[key];
@dmikey
dmikey / component.js
Created December 24, 2015 12:01
componentize your JS easy.
'use strict';
module.exports = function(template, data) {
this.data = function(data) {
this.oldnode = this.node;
for (var k in data) {
this[k] = data[k];
};
this.tag = this.tag || 'div';