Skip to content

Instantly share code, notes, and snippets.

View itzaks's full-sized avatar

Isak ✏ ⇝ itzaks

View GitHub Profile
@itzaks
itzaks / embedder.coffee
Created March 31, 2013 13:13
Helper for embedding an iframe right after this script node. Also includes some css and javascript insert methods. Can limit the iframe to specific size.
class Embed
embedded: false
width: 250
height: 250
name: "something"
baseURL: "//s3-eu-west-1.amazonaws.com/some-bucket"
constructor: (@script) ->
@width = @script.width if @script.width
@height = @script.height if @script.height
@itzaks
itzaks / server.coffee
Last active December 24, 2015 08:29
Brunch server file.
class Server
mongoose: require 'mongoose'
express: require 'express'
path = require 'path'
constructor: ->
@app = @express()
@app.use @express.static(path.resolve "public")
@app.use @express.bodyParser()
VALIDATIONS =
mobile_number: (val) -> val.match /[06]{1}[7]{1}[0-9]{8}/
zipcode: (val) -> val.match /^(s-|S-){0,1}[0-9]{3}\s?[0-9]{2}$/
email: (val) -> val.match /^\S+@\S+\.\S+$/
personnummer: (val) ->
console.log (val.match /[1-2][0|9][0-9]{2}[0-1][0-9][0-3][0-9][0-9]{4}/), val.length is 12
(val.match /[1-2][0|9][0-9]{2}[0-1][0-9][0-3][0-9][0-9]{4}/) and val.length is 12
module.exports = ($form, validation) ->
@itzaks
itzaks / pie-chart.coffee
Created April 23, 2014 15:55
Lightweight Pie Chart module
module.exports =
class Pie
pos: 0
colors: ['yellow', 'black']
constructor: (@canvas, {@yes, @no}) ->
@data = [@yes, @no]
@context = canvas.getContext("2d")
#uses underscore for reduce but just swap with vanilla js if needed
@total = _.reduce @data, (memo, num) -> memo + num
@draw()
@itzaks
itzaks / _mixins.jade
Created May 12, 2014 12:23
IE8 polyfill for 'background-size: cover'
- var background = function(url) {
- return "background-size: cover; background-image: url('" + url + "'); -ms-filter: \"progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + url + "', sizingMethod='scale')\";";
- }
@itzaks
itzaks / imghex.coffee
Created August 15, 2014 09:37
Html input(type=file) image to base64
module.exports = (file, cb) ->
valid = (/image\/(gif|jpg|jpeg|tiff|png)$/i).test file.type
return false if not valid
reader = new FileReader()
reader.onload = (e) ->
cb(e.target.result)
reader.readAsDataURL(file)
@itzaks
itzaks / space-talk.coffee
Last active August 29, 2015 14:05
Add mediator style pub/sub to space-pen views using flesch/psst.js
psst = require 'psst'
module.exports = require 'space-pen'
module.exports.EventView =
class EventView extends module.exports.View
subscriptions: null
initialize: ->
return unless @subscriptions
for subscription, method of @subscriptions
@itzaks
itzaks / readify.js
Last active August 29, 2015 14:06
Simple bookmarklet for injecting readability styles straight into the page.
(function() {
function loadScript(a,b){
var c=document.createElement('script');
c.type='text/javascript';c.src=a;
var d=document.getElementsByTagName('head')[0],done=false;
c.onload=c.onreadystatechange=function(){
if(!done&&(!this.readyState||this.readyState=='loaded'||this.readyState=='complete')){
done=true;
b()
}
@itzaks
itzaks / debounce.coffee
Created December 11, 2014 13:14
tiny coffeescript debounce function
debounce = (timeout, fn, timer = null) -> ->
clearTimeout timer
timer = setTimeout fn, timeout
@itzaks
itzaks / responsive-retina-image.styl
Created June 24, 2015 13:57
Render an image that scales nicely and keeps its proportions. Depends on nib's image-mixin for retina images.
img(src, width, height)
image(src)
background-size: contain
background-repeat: no-repeat
background-position: 50%
max-width: width
width: 100%
margin-left: auto
margin-right: auto