Skip to content

Instantly share code, notes, and snippets.

@jonknapp
jonknapp / image_path_tag.rb
Created September 19, 2014 18:38
Jekyll plugin to return <img> markup by only passing in the image filename and optional alt text. Image path is "/images/:year/:slug/:filename".
module Jekyll
class ImagePathTag < Liquid::Tag
@alt = nil
@url = nil
IMAGE_URL = /((https?:\/\/|\/)?(\S+))/i
IMAGE_URL_WITH_ALT = /((https?:\/\/|\/)?(\S+))(\s+)"(.*?)"/i
def initialize(tag_name, markup, tokens)
super
@jonknapp
jonknapp / .profile
Created September 19, 2014 18:38
Show if a Vagrant server is "on" or "off" in the command prompt if in a folder with a Vagrantfile. Code for http://jonknapp.com/2013/01/vagrant-status-in-the-command-line/
#
# Colors
#
RED="\[\033[0;31m\]"
YELLOW="\[\033[0;33m\]"
GREEN="\[\033[0;32m\]"
NORMAL="\[\033[0m\]"
DARK_PURPLE="\[\033[1;34m\]"
#
@jonknapp
jonknapp / gist_tab.rb
Created September 19, 2014 18:39
I forked the original (https://gist.github.com/803483#file-gist_tag-rb) since I was having issues with Markdown / Jekyll trying to parse the <noscript> content and completely screwing it up. Removed the <noscript> tags and instead I hide the content with js once the page loads.
require 'cgi'
require 'digest/md5'
require 'net/https'
require 'uri'
module Jekyll
class GistTag < Liquid::Tag
def initialize(tag_name, text, token)
super
@text = text
@jonknapp
jonknapp / image.js
Created September 19, 2014 18:42
Files used by High Resolution Images post at http://jonknapp.com/2013/01/high-resolution-images/
(function (window, devicePixelRatio, $, View, _) {
'use strict';
// I don't recommend adding objects on the window object, but it was quick.
window.ImageView = View.extend({
// Array of images that we will attempt to load.
// Images will be in priority order.
images: null,
@jonknapp
jonknapp / example.com-deploy
Created September 19, 2014 18:42
Amazon S3 user policy that allows the user to list the S3 buckets in the account, but only manage the files in the "example.com" bucket. Full post located at http://jonknapp.com/2013/01/deploying-jekyll-to-s3/
{
"Statement": [
{
"Action": [
"s3:ListAllMyBuckets"
],
"Effect": "Allow",
"Resource": "arn:aws:s3:::*"
},
{
@jonknapp
jonknapp / Gaurdfile
Created September 19, 2014 18:43
Mocking web requests when running specs in Guard only. If you run them through rspec (without setting the RSPEC_ENV environment variable to "guard") it will make the full web request.
guard 'rspec', :env => {'RSPEC_ENV' => 'guard'} do
# ...
end
@jonknapp
jonknapp / idonethis_import.rb
Created September 19, 2014 18:44
Import to Day One app from idonethis csv export
require 'cgi'
require 'csv'
require 'open3'
def readfile(file)
data = {}
CSV.foreach(file) do |row|
date = row[0]
text = row[1]
@jonknapp
jonknapp / browserify.js
Created September 19, 2014 18:44
running Exorcist with Grunt Browserify after bundle creation
// This will create a readable stream that we can pipe our bundle to Exorcist with
var stream = require('stream');
var grunt = require('grunt');
var exorcist = require('exorcist');
var createSourceMap = function(err, src, next) {
var mapfile = grunt.template.process('<%= folders.output %>/<%= filenames.js %>.map');
var s = new stream.Readable();
s._read = function noop() {};
@jonknapp
jonknapp / application.js
Created March 17, 2015 21:10
promises + addInitializer
var Application = {
addInitializer: function(func) {
return new Promise(func);
}
};
Promise.all([
Application.addInitializer(require('./initializers/something')),
Application.addInitializer(require('./initializers/something-else')),
Application.addInitializer(require('./initializers/blah'))
@jonknapp
jonknapp / Gruntfile.js
Last active August 29, 2015 14:23
Run tap/tape tests from within Grunt and throw errors appropriately.
grunt.registerMultiTask('tape', 'Run tap/tape tests from within grunt.', function () {
var done = this.async();
var faucet = require('faucet');
var tapParser = require('tap-parser');
var parser = tapParser(function (results) {
if (results.fail > 0) {
grunt.fail.warn(results.fail + ' test(s) have failed');
} else {
done();