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 / validators.md
Last active August 29, 2015 14:26
Validation Library

To define your validation rules, provide a Map. Keys are field names, values are either a validation rule, or an array of validation rules.

// one rule
const rules = new Map([
  ['name', required]
])

// multiple rules
const rules = new Map([
@danharper
danharper / how.md
Created June 26, 2015 11:17
enable Chrome Dev Tools debugging of PhoneGap Build apps on Android

Inside config.xml add the following attribute to the widget element:

xmlns:android="http://schemas.android.com/apk/res/android"

(For example, it looks like this for me:)

@danharper
danharper / demo.md
Last active January 20, 2024 16:09
Open native Maps apps on iOS and Android in Cordova
iOS (with pin, iOS will lookup address too and show that as label)
maps://?q=LAT,LNG
Android, no pin (just open at location)
geo:LAT,LNG
jQuery("ul.popover.level0").menuAim({
activate: function(row) { jQuery(row).addClass('active') },
deactivate: function(row) { jQuery(row).removeClass('active') },
rowSelector: 'li.level1.parent',
exitMenu: function() { return true; }
});
@danharper
danharper / query-params.php
Last active August 29, 2015 14:20
query params. experiment in something a little different
<?php
namespace param {
class QueryParam {
const SINGLE = 'single';
const MANY = 'many';
const MANY_CSV = 'csv';
public $queryField;
private $nullable = false;
@danharper
danharper / CatchAllOptionsRequestsProvider.php
Last active April 20, 2024 01:53
Lumen with CORS and OPTIONS requests
<?php namespace App\Providers;
use Illuminate\Support\ServiceProvider;
/**
* If the incoming request is an OPTIONS request
* we will register a handler for the requested route
*/
class CatchAllOptionsRequestsProvider extends ServiceProvider {
@danharper
danharper / decorators.js
Created April 9, 2015 22:15
ES7 Decorators
@ngInject('bus', '$ionicModal')
class Adder {
constructor(num) {
this.num = num
}
// order matters
// if you @swallow first, then @log won't log caught exceptions
@log
@swallow
@danharper
danharper / BorderedInput.js
Last active May 16, 2016 20:31
BorderedInput, with Material design style focus animation. Preview: https://i.imgur.com/Fek7rXF.gif
// note there may be a better way to abuse flexbox than this :)
var React = require('react-native')
var { View, TextInput } = React
var BorderedInput = React.createClass({
getInitialState() {
return { i: 0 }
},
async function sleep(ms) {
return new Promise(r => setTimeout(r, ms))
}
async function foo() { console.log('s foo'); await sleep(2000); console.log('d foo'); return 'foo'; }
async function bar() { console.log('s bar'); await sleep(1000); console.log('d bar'); return 'bar'; }
async function baz() { console.log('s baz'); await sleep(2000); console.log('d baz'); return 'baz'; }
async function run() {
console.log('start')