Skip to content

Instantly share code, notes, and snippets.

Avatar

Hunter Cassidy hunterc

View GitHub Profile
@hunterc
hunterc / validator.js
Created Feb 3, 2014
Form field validator: currently requires a fieldmap with jquery element
View validator.js
(function (global) {
'use strict';
var Validator = function Validator() {
this.schemas = {
text: {
maxLength: function (val, prop) {
return {
success: val.length <= prop.maxLength,
msg: 'Value exceeds maximum length: ' + prop.maxLength + '.'
@hunterc
hunterc / stringUtil.js
Last active Aug 29, 2015
JS String startsWith, endsWith methods
View stringUtil.js
var stringUtil = (function(global)) {
// prototype modifiers
if (typeof String.prototype.startsWith !== 'function') {
String.prototype.startsWith = function(str) {
return this.slice(0, str.length) === str;
};
}
if (typeof String.prototype.endsWith !== 'function') {
@hunterc
hunterc / gist:c2e12c4a99f43682fd7c
Created Nov 18, 2014
npm tarball url bug dump
View gist:c2e12c4a99f43682fd7c
0 info it worked if it ends with ok
1 verbose cli [ 'node',
1 verbose cli '/usr/local/bin/npm',
1 verbose cli 'install',
1 verbose cli 'https://api.github.com/repos/kiplic/tardis/tarball/master' ]
2 info using npm@2.1.8
3 info using node@v0.10.33
4 verbose node symlink /usr/local/bin/node
5 silly cache add args [ 'https://api.github.com/repos/kiplic/tardis/tarball/master',
5 silly cache add null ]
@hunterc
hunterc / filterlist.js
Created Dec 5, 2014
react component to create filter list
View filterlist.js
/** @jsx React.DOM */
var itemList = [
'Apples',
'Pie',
'Brocooli',
'Chicken',
'Duck',
'Eggs',
'Fish',
@hunterc
hunterc / example_model.js
Created Jan 19, 2015
example mongoose model
View example_model.js
var mongoose = require('mongoose'),
Schema = mongoose.Schema;
var fields = {
// fields for model
name: String
};
var ModelSchema = new Schema(fields);
View juggle-async.js
var http = require('http');
var urls = process.argv.slice(2);
var results = [];
var done = 0;
function printResults() {
for (var i = 0; i < 3; i++) console.log(results[i]);
}
View spiral_matrix.py
!#/usr/bin/python
import sys
file = open(sys.argv[1])
lst = []
for line in file:
lst.append(line.strip().split())
@hunterc
hunterc / django_complete.sh
Last active Aug 29, 2015
django auto complete
View django_complete.sh
brew tap homebrew/completions
brew install django-completion
# resource your profile
source ~/.bashrc
@hunterc
hunterc / reducers.js
Last active Aug 31, 2015
reducer stores
View reducers.js
function initialState() {
return [];
}
function selectReducer(state = initialState(), action) {
switch (action.type) {
case SELECT_OPTION:
return state.map(option =>
option.id === action.id
? { ...option, selected: true }
View routing-bug.js
import React from 'react';
import { render } from 'react-dom';
import { createStore, combineReducers } from 'redux';
import { Provider } from 'react-redux';
import { Router, Route, IndexRedirect } from 'react-router';
import { useBasename, createHistory } from 'history';
import { syncReduxAndRouter, routeReducer } from 'redux-simple-router';
const reducer = combineReducers({
routing: routeReducer
You can’t perform that action at this time.