Skip to content

Instantly share code, notes, and snippets.

@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 :=)
@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 / 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 : {
function loadFacebook() {
$script("http//connect.facebook.net/en_US/all.js#xfbml=1");
}
minwidth(600, loadFacebook);
minwidth(480, null, enhanceMobile, true);
minwidth(480, moveSomething, moveItBack);
var sidebar = document.getElementById("sidebar");
var sidebarElements = document.getElementsByClassName("sidebarElements");
// here is the function call:
relocate(480, sidebarElements, sidebar);
@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);
String.prototype.toUnicode = function (){
function pad(t) {
return t.length == 4 ? t : pad("0" + t);
}
var r="";
for (var i = 0; i < this.length; i++) {
r += "\\u" + pad(this.charCodeAt(i).toString(16));
}
return r;
}
@eikes
eikes / date.format.js
Created February 15, 2012 13:34
Copy of amazing date format js script by Steven Levithan: http://blog.stevenlevithan.com/archives/date-time-format
/*
* Date Format 1.2.3
* (c) 2007-2009 Steven Levithan <stevenlevithan.com>
* MIT license
*
* Includes enhancements by Scott Trenda <scott.trenda.net>
* and Kris Kowal <cixar.com/~kris.kowal/>
*
* Accepts a date, a mask, or a date and a mask.
* Returns a formatted version of the given date.