Skip to content

Instantly share code, notes, and snippets.

@danharper
danharper / Redirector.js
Last active August 29, 2015 14:26
Mess to transition in async action creators for redux-react-router
import { Component, PropTypes } from 'react'
import { connect } from 'react-redux'
import { transitionTo } from 'redux-react-router'
const NEXT_URL = 'REDIRECTOR(NEXT_URL)'
const CLEAR_NEXT_URL = 'REDIRECTOR(CLEAR_NEXT_URL)'
export const transitionNext = url => ({ type: NEXT_URL, payload: url })
export const clearNextUrl = () => ({ type: CLEAR_NEXT_URL })
@danharper
danharper / edit.erb
Created March 22, 2011 16:49
Edit View
<% if @note %>
<form action="/<%= @note.id %>" method="post" id="edit">
<input type="hidden" name="_method" value="put">
<textarea name="content"><%=h @note.content %></textarea>
<input type="checkbox" name="complete" <%= "checked" if @note.complete %>>
<input type="submit">
</form>
<p><a href="/<%= @note.id %>/delete">Delete</a></p>
<% else %>
<p>Note not found.</p>
@danharper
danharper / helper.js
Created February 6, 2012 21:31
Handlebars Conditional Helper
Handlebars.registerHelper('if_task_active', function(options) {
var state = this.model.state_id;
if (state == 300) {
return options.fn(this);
}
return options.inverse(this);
});
@danharper
danharper / helper.js
Created February 6, 2012 22:43
Handlebars Conditional Helper with Arguments
Handlebars.registerHelper('if_task_state', function(options) {
var states = options.hash.is.split(',')
, r = false
;
_.each(states, function(state) {
if (state == this.model.state)
r = true;
}, this);
@danharper
danharper / wrapper.php
Created February 20, 2012 21:55
FuelPHP package wrapper
<?php
public static function __callStatic($method, $arguments)
{
return call_user_func_array(array(self::$_instance, $method), $arguments);
}
@danharper
danharper / index.html
Created July 16, 2012 22:43
A web page created at CodePen.io
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Simple Styled Radio Inputs &middot; CodePen</title>
<!--
Copyright (c) 2012 Dan Harper, http://codepen.io/danharper
Permission is hereby granted, free of charge, to any person obtaining
@danharper
danharper / TimestampToDate.scpt
Last active October 8, 2015 10:47 — forked from clooth/TimestampToDate.scpt
Applescript to display real date of selected timestamp
on run {input, parameters}
tell application "System Events"
set activeApp to name of first process whose frontmost is true
end tell
set _timestamp to (input as string)
tell application activeApp
set realDate to ((do shell script "date -r " & _timestamp) as string)
@danharper
danharper / unblockus
Created August 22, 2012 10:54
Toggle Mac Wi-Fi DNS settings for using Unblock-Us.
function unblockuson() {
sudo networksetup -setdnsservers "Wi-Fi" 208.122.23.22 208.122.23.23
sudo networksetup -setairportpower "en1" "off"
sudo networksetup -setairportpower "en1" "on"
echo "Unblock-Us: ENABLED"
}
function unblockusoff() {
sudo networksetup -setdnsservers "Wi-Fi" "empty"
sudo networksetup -setairportpower "en1" "off"
@danharper
danharper / gist:4247146
Created December 9, 2012 21:37
Removing Browser's Print Header/Footer
@page {
margin: .312in .312in .322in;
}
@media print {
html {
margin: 0 .1in;
}
}
@danharper
danharper / after.blade.php
Created March 20, 2014 13:02
Declarative Blade Extensions
@usingPerRow(4)
@foreach ($images as $image)
@incrementPerRow()
@whenStartOfRow
<tr>
@closeStartOfRow
<td><img src="{{ $image->url }}"></td>