Skip to content

Instantly share code, notes, and snippets.

@eikes
eikes / getElementWidth.js
Created April 23, 2012 13:29
Determine html element width without jquery
// Function to determine the width of any element in pixel:
getElementWidth = function (node) {
var ow = node.offsetWidth,
cs = node.currentStyle && node.currentStyle["width"]
|| getComputedStyle && getComputedStyle(node, null).getPropertyValue("width"),
result = parseFloat(ow || cs);
if (cs && cs.match(/%/))
return (parseFloat(cs) / 100) * getElementWidth(node.parentNode);
if (isNaN(result) || result == 0)
return getElementWidth(node.parentNode);
var sidebar = document.getElementById("sidebar");
var sidebarElements = document.getElementsByClassName("sidebarElements");
// here is the function call:
relocate(480, sidebarElements, sidebar);
minwidth(480, moveSomething, moveItBack);
minwidth(480, null, enhanceMobile, true);
function loadFacebook() {
$script("http//connect.facebook.net/en_US/all.js#xfbml=1");
}
minwidth(600, loadFacebook);
@eikes
eikes / settings.js
Created December 10, 2012 11:49
facetedsearch settings with state object
var settings = {
state : {
"orderBy" : "lastname",
"filters" : {
"category" : ["Bird"],
"continent" : ["Africa"]
}
},
items : example_items,
facets : {
@eikes
eikes / run_phoenix_on_ubuntu.sh
Created December 29, 2015 00:47
run phoenix on ubuntu
wget https://packages.erlang-solutions.com/erlang-solutions_1.0_all.deb && sudo dpkg -i erlang-solutions_1.0_all.deb
sudo apt-get update
sudo apt-get install git esl-erlang elixir postgresql nodejs nodejs-legacy npm
sudo npm -g install brunch@1
mix local.hex
mix archive.install https://github.com/phoenixframework/phoenix/releases/download/v1.1.1/phoenix_new-1.1.1.ez
git clone https://github.com/eikes/phoenix_guides_server.git
@eikes
eikes / gist:1269911
Created October 7, 2011 09:41
Play MP3 in the background on iPhone in Safari browser
var mp3 = document.createElement("audio");
mp3.setAttribute('src', 'http://example.com/track.mp3');
mp3.load();
document.documentElement.appendChild(mp3);
mp3.play();
// use mp3.pause() to pause :=)
{% block collection_widget %}
{% spaceless %}
<div class="collection">
{% if prototype is defined %}
{% set attr = attr|merge({'data-prototype': block('collection_item_widget') }) %}
{% endif %}
<div {{ block('widget_container_attributes') }}>
{{ form_errors(form) }}
<ul>
{% for prototype in form %}
@eikes
eikes / imgpreload.js
Created October 20, 2012 23:23
JavaScript image preloader with callback
/*
* Copyright (C) 2012 Eike Send
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to
* deal in the Software without restriction, including without limitation the
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
* sell copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*