Skip to content

Instantly share code, notes, and snippets.

View codepunkt's full-sized avatar

Christoph Werner codepunkt

View GitHub Profile
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 / 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: {
@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
#!/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 / _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;
}
@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');
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 / kill_port.sh
Last active June 7, 2016 11:22
Kill process running on a port
#!/bin/bash
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[0;33m'
NC='\033[0m'
if [ $# -eq 0 ] ; then
echo -e "${RED}Error: No port given${NC}"
exit 1
fi
@codepunkt
codepunkt / react-motion-preset-keyframes.styl
Last active January 21, 2017 00:35
react-motion preset keyframe generator in stylus
sqrt(x)
if x == 0
result = 0
else
result = 4
for i in (0..10)
result = ((result + (x / result)) / 2)
spring-noWobble(t)
return 2.71828 ** (-13 * t) * (2.71828 ** (13 * t) - 13 * sin(t) - cos(t))
@codepunkt
codepunkt / config.json
Last active October 18, 2022 16:04
Host react app built with webpack in non-root directory
{
"basePath": "/"
}