Skip to content

Instantly share code, notes, and snippets.

@timaschew
timaschew / gulp-task.js
Last active December 4, 2021 18:34
proxy browser-sync server with express and secure everything with basic auth
// just add pass server as your task function
// Start a server with LiveReload to preview the site in
const OUTPUT_PARENT = 'dist'
const OUTPUT_DIRECTORY = OUTPUT_PARENT + '/browser-sync'
function server(done) {
browser.init({
server: {
directory: true,
@timaschew
timaschew / SynchronousValidationForm.js
Last active February 18, 2016 23:01
redux-form test
import React, {Component, PropTypes} from 'react';
import {reduxForm} from 'redux-form';
export const fields = ['username', 'email', 'age'];
const validate = values => {
const errors = {};
if (!values.username) {
errors.username = 'Required';
} else if (values.username.length > 15) {
errors.username = 'Must be 15 characters or less';
@timaschew
timaschew / webpack.config.js
Created February 10, 2016 20:35
postcss, precss, cssnext, sass
module: {
loaders: [
{
test: /\.js$/,
loaders: [ 'babel' ],
exclude: /node_modules/,
include: path.join(__dirname, 'src')
},
{
test: /\.scss$/,
@timaschew
timaschew / error-stack.log
Created February 10, 2016 12:22
webpack postcss + precss and foundation
ERROR in ./~/css-loader!./~/postcss-loader?parser=postcss-scss!./src/styles/styles.scss
postcss-import: /Users/timaschew/dev/redux-boilerplate/node_modules/foundation-sites/scss/foundation.scss:8:1: Unknown word
// Sass utilities
^
@import 'util/util';
ERROR in ./~/css-loader!./~/postcss-loader?parser=postcss-scss!./src/styles/styles.scss
Module build failed: TypeError: Cannot read property 'toString' of undefined
at new Input (/Users/timaschew/dev/redux-boilerplate/node_modules/postcss/lib/input.js:31:23)
@timaschew
timaschew / deepFromFlat.js
Created February 4, 2016 19:52
underscore deepFromFlat
# https://github.com/Clever/underscore.deep/blob/9835bcb0fbb193649095d1444d99ff46f51f8149/underscore.deep.coffee#L126
# Takes an object with keys with dot.notation and deepens it into dot{notation:{}}
deepFromFlat: deepFromFlat = (o) ->
oo = {}
t = undefined
parts = undefined
part = undefined
for k of o
t = oo
@timaschew
timaschew / test.js
Created January 18, 2016 01:06
This function checks if an array is part of another array. In comparision to underscore and lodash it also checks the order and can also handle non uniq arrays
const expect = require('chai').expect
import utils from './utils'
describe('utils', () => {
it('containsSubArray', function() {
let result = utils.containsSubArray([1,2,3,4,1,5,5,6,7], [4,1,5,5,6])
expect(result).equal(true)
result = utils.containsSubArray([4,1,5,5,6,7], [4,1,5,5,6])
expect(result).equal(true)
@timaschew
timaschew / index.js
Last active January 17, 2016 17:56
requirebin sketch
// require() some stuff from npm (like you were using browserify)
// and then hit Run Code to run it on the right
var j = require('jquery');
console.log('j:', j);
console.log('global polution check', window.$, window.jQuery);
// OPEN YOUR BROWSER CONSOLE
@timaschew
timaschew / js fill sequence.js
Created December 21, 2015 10:02
fill array with a sequence
Array.apply(0, Array(8)).map(function(_, i) { return i; })
var timeoutRef = null;
jQuery.post(ajaxurl, data, function(response) {
result = $(response).find('success').first().text();
if(result == 'true') {
jQuery('.iamhuman_message').hide();
answer_field.val(selection_string);
jQuery('#alt_submit').click();
} else {
// display error message
clearTimeout(timeoutRef);