Skip to content

Instantly share code, notes, and snippets.

View enyo's full-sized avatar
🙌
Primarily working on Pausly

Matias Meno enyo

🙌
Primarily working on Pausly
View GitHub Profile
// Get the template HTML and remove it from the doument.
var previewNode = document.querySelector("#template");
previewNode.id = "";
var previewTemplate = previewNode.parentNode.innerHTML;
previewNode.parentNode.removeChild(previewNode);
var myDropzone = new Dropzone(document.body, { // Make the whole body a dropzone
url: "/target-url", // Set the url
thumbnailWidth: 80,
thumbnailHeight: 80,
<!-- HTML heavily inspired by http://blueimp.github.io/jQuery-File-Upload/ -->
<div class="table table-striped" class="files" id="previews">
<div id="template" class="file-row">
<!-- This is used as the file preview template -->
<div>
<span class="preview"><img data-dz-thumbnail /></span>
</div>
<div>
<p class="name" data-dz-name></p>

tmux cheatsheet

As configured in my dotfiles.

start new:

tmux

start new with session name:

@enyo
enyo / package.json
Created January 5, 2014 20:50
gulp package.json
{
"name": "project-tools"
, "version": "0.0.1-dev"
, "private": true
, "devDependencies": {
"gulp": "*",
"gulp-myth": "*"
}
}
@enyo
enyo / changelog.sh
Created July 3, 2013 13:04
Print changelog to use for Github releases. (Goes through all commits, and shows the one with a #changelog hashtag)
#!/bin/bash
#echo git log $1...$2 --pretty=format:'<li> <a href="http://github.com/jerel/<project>/commit/%H">view commit &bull;</a> %s</li> ' --reverse | grep "#changelog"
firstTag=$(git tag | tail -2 | head -1)
secondTag=$(git tag | tail -1)
cmd=$(basename $0)
if [ "$1" == "-h" ]
then
@enyo
enyo / preloader.js
Last active March 15, 2024 13:42
Preloading images with jQuery
/**
* Preloads the image, and invokes the callback as soon
* as the image is loaded.
*/
var preload = function(src, callback) {
// Create a temporary image.
var img = new Image();
// Invoke the callback as soon as the image is loaded
// Has to be set **before** the .src attribute. Otherwise
@enyo
enyo / gist:4726916
Created February 6, 2013 23:37
Tweek dropzone to use another container for file previews
Dropzone.myDropzone.options = {
addedfile: function(file) {
file.previewTemplate = $(this.options.previewTemplate);
this.element.find(".previews").append(file.previewTemplate);
file.previewTemplate.find(".filename span").text(file.name);
file.previewTemplate.find(".details").append($("<div class=\"size\">" + (this.filesize(file.size)) + "</div>"));
}
};

EventListener Polyfill

Is IE8 your new IE6? Level the playing field with polyfills.

This script polyfills addEventListener, removeEventListener, and dispatchEvent. It is less than half a kilobyte minified and gzipped.

addEventListener

addEventListener registers a single event listener on a single target.

//addEventListener polyfill 1.0 / Eirik Backer / MIT Licence
(function(win, doc){
if(win.addEventListener)return; //No need to polyfill
function docHijack(p){var old = doc[p];doc[p] = function(v){return addListen(old(v))}}
function addEvent(on, fn, self){
return (self = this).attachEvent('on' + on, function(e){
var e = e || win.event;
e.preventDefault = e.preventDefault || function(){e.returnValue = false}
e.stopPropagation = e.stopPropagation || function(){e.cancelBubble = true}
@enyo
enyo / storefile.js
Last active December 10, 2015 22:29
var path = require("path");
exports.media = function(req, res, next) {
var file = req.files.media_upload;
// code to handle file here:
// file should already be in the right location
// The path, this file has been saved at should be:
file.path;
// To get only the filename of this path: