Skip to content

Instantly share code, notes, and snippets.

View KrofDrakula's full-sized avatar

Klemen Slavič KrofDrakula

View GitHub Profile
@KrofDrakula
KrofDrakula / SelectBox.js
Created June 15, 2011 10:43
Select box replacement
(function($) {
$(function() {
var selectBoxes = $('select');
selectBoxes.each(function() {
var $select = $(this).hide(),
$proxy = $('<ul class="selectbox"/>').insertAfter($select);
$select.find('option').each(function() {
// we iterate through the options and create a list item with data-value as value
$proxy.append('<li data-value="' + this.value + '">' + $(this).text() + '</li>');
@KrofDrakula
KrofDrakula / .htaccess
Created July 21, 2011 13:35
Hash redirect
RewriteEngine On
# Rewrite only if request does not map to a physical file
RewriteCond %{REQUEST_FILENAME} !-f
# Reroute all requests to our index.php file
RewriteRule ^(.*)$ index.php [QSA,L]
Backbone = require 'backbone'
class Router extends Backbone.Router
routes:
':module/*path' : 'dispatch'
dispatch: (module, path) =>
console.debug module, path
@KrofDrakula
KrofDrakula / polyfill-request-animation-frame.js
Created October 1, 2011 12:49
Polyfills the `requestAnimationFrame` function for all browsers.
(function(context) {
var exts = ['', 'webkit', 'moz', 'o', 'ms'];
function lookup(name) {
var n, i;
for (i in exts) {
n = lcfirst(exts[i] + ucfirst(name));
if (context[n]) return n;
}
return false;
@KrofDrakula
KrofDrakula / humanize.coffee
Created October 17, 2011 12:51
A utility function for humanizing numbers
humanize = (value, precision = 2) ->
if value < 1e3
return value.toString()
if value < 1e6
return (value / 1e3).toPrecision(precision) + 'k'
if value < 1e9
return (value / 1e6).toPrecision(precision) + 'M'
if value < 1e12
return (value / 1e9).toPrecision(precision) + 'G'
(value / 1e12).toPrecision(precision) + 'T'
@KrofDrakula
KrofDrakula / RaphaelExtensions.coffee
Created October 19, 2011 15:19
Extends Raphaël 2.0 with set operations to help with manipulating sets
# Returns the closest element in the given set.
# Compares the centers of the elements in the set to determine
# the closest element. Returns the Raphaël element closest
# to the point.
#
# Usage: mySet.closestTo(123,456).attr fill: 'red'
Raphael.st.closestTo = (x, y) ->
el = null
dist = Infinity
@forEach (elm) ->
@KrofDrakula
KrofDrakula / description.md
Created November 9, 2011 10:01
New topic for #wwwh

Adaptive Web Applications

Because finding good examples for adaptive algorithms while keeping it under an hour and grokkable, I've decided to refocus my topic to adaptive web apps.

This isn't your vanilla responsive web design as you're used to. The topic will cover adapting UI logic to the current device and controlled by media queries and device features. This enables you to adapt your UI logic to several different devices and capabilities in a single code base by using a Javascript framework (to be announced, since I still have to write it ;)) to map actions to the UI.

And yes, the talk can be in English if you're so inclined.

@KrofDrakula
KrofDrakula / gist:1452006
Created December 9, 2011 15:34
#wwwh on Dec 14 2011 @ Cyberpipe, Ljubljana

Responsive Web Applications

In this lecture we'll explore the concept of responsive design applied to web application behaviour. We'll explore the coming paradigm shift in UI design and UX planning and try to probe the future with interaction models that are just now becoming available or will become available in the near future. You think touch is the only new interaction model? Think again.

To make things concrete, we'll also take a look at a proof-of-concept implementation of a web application to see just how we can use existing libraries to respond differently given an interaction context and identify areas which can helps us in developing better concepts and tools to manage this new layer of complexity.

The talk will be in English and all code shown will be open sourced prior or during the talk.

About the speaker: http://about.me/klemen.slavic, @krofdrakula (#responsiveapps)

To calculate flat shading (an approximation that works well for small flat faces), you need:

  • a vector pointing towards the light source from the center of the surface you want to shade,
  • a vector representing the normal of the surface to be rendered.

The first one is easily calculated:

var faceCenter = [x1, y1, z1];
var light = [x2, y2, z2];
@KrofDrakula
KrofDrakula / BaseModel.coffee
Created December 30, 2011 08:14
Getters and setters for Backbone models
Backbone = require 'backbone'
class BaseModel extends Backbone.Model
constructor: ->
super
model = @
@data = data = {}
for key of @defaults
do (key) ->