Skip to content

Instantly share code, notes, and snippets.

View bebraw's full-sized avatar

Juho Vepsäläinen bebraw

View GitHub Profile
@bebraw
bebraw / mixin.css
Created December 27, 2011 17:23
more.js blog post examples part 2
#header {
border-radius: 5px;
-webkit-border-radius: 5px;
-moz-border-radius: 5px;
}
#footer {
border-radius: 10px;
-webkit-border-radius: 10px;
-moz-border-radius: 10px;
}
@bebraw
bebraw / initial_transform.js
Created December 27, 2011 12:21
more.js blog post examples
#!/usr/bin/env node
var fs = require('fs');
var source = process.argv.splice(2)[0];
var target = source.substring(0, source.lastIndexOf('.')) + '.css';
fs.readFile(source, 'utf-8', function(err, data) {
if (err) throw err;
var analyze = function(input) {
@bebraw
bebraw / drag.js
Created December 16, 2011 16:30
Simple dragging algo borrowed from my drawing app
define(function() {
return {
meta: {
tooltip: 'Drags the canvas around',
category: 'canvas'
},
selected: function() {
var $elem = $$('.paintCursor')[0];
this._oldPaintCursor = $elem.getStyle('cursor');
from __future__ import print_function
from functools import partial
from questions import boolean, choice, match
def ask(questions):
def _fill(i):
... # this just attaches some extra data to i so we can avoid checks later
def _input():
import subprocess
import sys
def convert(source, from_format, to_format):
# original version: http://osiux.com/html-to-restructured-text-in-python-using-pandoc
# supported formats at http://johnmacfarlane.net/pandoc/
# raises OSError if pandoc is not found!
p = subprocess.Popen(['pandoc', '--from=' + from_format, '--to=' + to_format],
stdin=subprocess.PIPE, stdout=subprocess.PIPE
)
fibo = scan(0, 1, lambda a, b: a + b) # fibonacci sequence (iterator)
part = sliceable(fibo)[10:20] # let's slice that iterator to a list
# chaining func ops (just map, filter and reduce for now)
chainable([1, 2, 3]).map(lambda x: x * 2).filter(lambda x: x > 3).val() == [4, 6]
@bebraw
bebraw / checker.js
Created September 29, 2011 15:39
Invariant checker for JavaScript
function checkArguments(errors, errorPrefix, suppressWarning) {
errorPrefix = errorPrefix? errorPrefix + ': ': '';
var gotError = false;
for(var argName in errors) {
// remember to attach forEach to Array or replace this with a more generic
// definition
errors[argName].forEach(function(check) {
if(check.invariant) {
@bebraw
bebraw / inf.py
Created September 24, 2011 10:43
Infinite list for python
class InfList(object):
def __init__(self, *items):
self._rule = (lambda i, a, b: 2 * b - a) if len(items) == 2 else items[2]
self._items = list(items[0:2])
def __getitem__(self, k):
if k >= len(self._items):
self._calc_items(k)
return self._items[k]
@bebraw
bebraw / gist:1000256
Created May 31, 2011 09:59
lovely.io debug log
Listening: http://127.0.0.0:3000
Press Ctrl+C to hung up
Sending: /index.html (text/html)
Sending: /shared.css -> ~/.lovely/server/shared.css
Serving: /core.js -> ~/.lovely/packages/core/current/build/core-src.js
Error: Cannot find module 'stylus'
at Function._resolveFilename (module.js:320:11)
at Function._load (module.js:266:25)
at require (module.js:348:19)
@bebraw
bebraw / generate_site.php
Created May 24, 2011 11:45
Precompiler thingy for Dwoo (converts templates to static HTML)
<?php
include('src/dwoo/dwooAutoload.php');
/*
* This script converts a bunch of Dwoo templates to proper HTML.
* Execute it like this "php generate_site.php".
*
* Use this file to inject variables to your templates. In order to make it
* easier to deal with paths, I defined "pathPrefix" variable. It contains
* prefix relative to the root. This in turn may be used to get some nice