Skip to content

Instantly share code, notes, and snippets.

View codepunkt's full-sized avatar

Christoph Werner codepunkt

View GitHub Profile
function onlyUnique(value, index, self) {
return self.indexOf(value) === index;
}
function findMatchingRoutes(routes, urlPath, ancestors) {
var result = [];
ancestors = ancestors || [];
routes.forEach(function (route) {
@codepunkt
codepunkt / index.js
Last active August 29, 2015 14:17
Async form validation in ampersand
// Example of async form validation in ampersand
// Has default `ampersand-input-view` clientside validation.
// If clientside validation passes, async validation is called 1 sec after input to check if given username exists
var FormView = require('ampersand-form-view');
var InputView = require('ampersand-input-view');
var debounce = require('amp-debounce');
var extend = require('amp-extend');
@codepunkt
codepunkt / _px-to-rem.scss
Last active August 29, 2015 14:16
px to rem mixin
@function px-to-rem($val, $base: 16) {
// if it's a unitless number
@if type-of($val) == number and unitless($val) {
// don't convert 0
@if $val == 0 {
@return 0;
}
// assume its px and convert it to rem based on $base document font-size
@return #{$val / $base}rem;
}
#!/bin/sh
# Alot of these configs have been taken from the various places
# on the web, most from here
# https://github.com/mathiasbynens/dotfiles/blob/master/.osx
# Set the colours you can use
black='\033[0;30m'
white='\033[0;37m'
red='\033[0;31m'
@codepunkt
codepunkt / gist:3b52d707ea1f726d471c
Created February 2, 2015 09:37
Bookmarklet: toggle website styles
javascript:(function(d,g,a,b,c,e,f,h,n,t,u,w,x){f=function(e,o,k){for(k in o)e.setAttribute(k,o[k])};c=function(e){return d.createElement(e)};n=function(s){return d.createTextNode(s)};a=function(e,c,k){for(k in c)e.appendChild(c[k])};w=c(g);h=c(g);t=n('Toggle Style-Elements');u=c('ul');b=d.querySelector('body');x='position:fixed;top:0;right:0;z-index:99999;margin:0;padding:0;background:#f4fff4;color:#99ad85;font:14px Helvetica,Arial,sans-serif;border:1px solid #bada55;border-top-width:0;border-right-width:0;border-bottom-left-radius:10px;';e=d.getElementById('tcss');if(b&&e)f(e,{style:x+(e.style.display=='none'?'':'display:none')});else if(b){f(w,{id:'tcss',style:x});f(h,{style:'font:20px Georgia,serif;padding:10px;margin:0;background:#dae7da;color:#693'});f(u,{style:'margin:0;padding:10px;list-style-type:disc'});f(u,{style:'margin:0;padding:10px;list-style-type:disc;'});a(b,[w]);a(w,[h,u]);a(h,[t]);[].slice.call(d.styleSheets).forEach(function(s,i,l,m,y,z){y='margin:0 0 0 20px;padding:0;cursor:pointer;line-h
@codepunkt
codepunkt / prereq_test.js
Last active August 29, 2015 14:10
Using prereqs in Hapi 7: Inline functions vs registered server methods.
var server = new (require('hapi')).Server('localhost', 8000);
server.method('registered', function(request, reply) {
console.log('registered', reply());
});
server.route({
method: 'GET',
path: '/',
config: {
plugin.method('users.validate', function(request, reply) {
User.find({ $or: [
{ email: request.payload.email },
{ username: request.payload.username }
]}, function(err, user) {
if (err || user) {
return reply({ error: 'db error or username/email exists' }).takeover();
}
reply();
});
@codepunkt
codepunkt / dabblet.css
Created November 28, 2013 16:02
Untitled
.outer {
height: 400px;
overflow: auto;
position: relative;
width: 200px;
}
.inner {
height: 1200px;
zoom: 1;
}
class TodoModel
constructor: ->
@todos = []
@callbacks = []
add: (name) ->
@todos.push name: name, completed: false
@handleChange 'add', name
onChange: (callback) ->
@callbacks.push callback
handleChange: (type, value) ->
@codepunkt
codepunkt / index.html
Created February 1, 2013 14:16
Russian Roulette in SVG
<body>
<svg xmlns:xlink="http://www.w3.org/1999/xlink">
<a>
<text y="1em">Click me</text>
<animate attributeName="xlink:href" values="#;#;#;#;#;javascript:alert('Bang!')" begin="0s" dur="0.1s" fill="freeze" repeatCount="indefinite"/>
</a>
</svg>
</body>