Skip to content

Instantly share code, notes, and snippets.

View jhammann's full-sized avatar
👐

Jeroen Hammann jhammann

👐
View GitHub Profile
@jhammann
jhammann / geocode_cells.js
Created October 24, 2016 08:12
Google Spreadsheet script for finding lat&lng and/or provinces (NL)
// Function to find the latitude and longitude of a location.
function geocodeSelectedCells() {
var sheet = SpreadsheetApp.getActiveSheet();
var cells = sheet.getActiveRange();
// Must have selected 4 columns (Street, City, Lat and Lng).
// Lat and Lng may ofcourse be empty (but you have to select them anyway).
// Must have selected at least 1 row.
if (cells.getNumColumns() != 4) {
@jhammann
jhammann / 00.howto_install_phantomjs.md
Created May 30, 2016 09:26 — forked from julionc/00.howto_install_phantomjs.md
How to install PhantomJS on Debian/Ubuntu

How to install PhantomJS on Ubuntu

Version: 1.9.8

Platform: x86_64

First, install or update to the latest system software.

sudo apt-get update
sudo apt-get install build-essential chrpath libssl-dev libxft-dev
@jhammann
jhammann / countdown_timer.js
Created April 24, 2014 12:06
If you use the great jquery countdown plugin with a datetime object from you database you may encounter some invalid date object errors in Firefox and/or IE. This code takes care of that issue by using a regex. Make sure your countdown_date string datetime is like the one used in this code.
// jquery countdown: http://keith-wood.name/countdown.html
var countdown_date = "07-05-1990 02:00";
var dateRegex = countdown_date.match(/(\d{2})-(\d{2})-(\d{4}) (.*)/);
var newDate = dateRegex[3] + "/" + dateRegex[2] + "/" + dateRegex[1] + " " + dateRegex[4];
var date = new Date(newDate);
$(".countdown-timer").countdown({until: date, format: "YODH", padZeroes: true});
@jhammann
jhammann / ember-active.html
Created March 27, 2014 13:28
Ember adds an active class to every element which corresponds to the current route. I wanted to add an active class to the parent element because Bootstrap wants the active class on a list-item but the anchor is needed too for styling.
{{#link-to "about" tagName="li" href="false"}}<a {{bind-attr href="view.href"}}>About</a>{{/link-to}}
@jhammann
jhammann / youtube-trigger.js
Created March 11, 2014 09:20
I want to execute some Javascript when a YouTube iframe changes its state (paused, stopped, played etc). You need to include the YouTube player API and make sure you enable it in your iframe embed code. This code works for multiple iframes on the same page.
$(".latest_work2 .swiper").on("change-class", function(){
// if the swiper div has the class 'pause' (which it receives when a YT video is not playing) it stops the cycle
if (slideshow2.slides.length > 3){
if ($(".latest_work2 .swiper").hasClass("pause")){
slideshow2.stopAutoplay()
} else {
slideshow2.startAutoplay()
}
}
});
@jhammann
jhammann / _container.html.haml
Created March 3, 2014 13:01
I had to create a container with repeatable border-backgrounds. I made a separate partial with some locals (for additional classes and IDs) which is rendered by Rails.
.container{class: "#{classes}", id: "#{ids}"}
.container_top
.container_top_left_corner
.container_top_border
.container_top_right_corner
.container_left
.container_content
= yield
.container_right
.container_bottom
@jhammann
jhammann / span_capitalize_helper.rb
Created September 11, 2013 14:46
A ruby helper that puts the first letter of a string (like a name) in a span to give it a special styling. For example: you want the first letter of a lastname in a special font, this helper creates a span that enables that.
def span_capitalize(string)
name = string.match(/(^[a-z])(.*)/i)
first_letter = name[1]
rest = name[2]
content_tag(:span, first_letter) + rest
end
@jhammann
jhammann / info_toggle.html.haml
Last active December 22, 2015 17:38
I have a title which has to be clicked on to show some information. The title not only contains text but also contains an image of an arrow that is down when the text isn't visible and has to be changed to up when the text is visible. Normally you would do this by changing the source attribute but working with Rails and the asset pipeline can pr…
%h2
= link_to "javascript:void(0);", class: "info" do
Information
= image_tag "arrowDown.jpg"
= image_tag "arrowUp.jpg", style: "display:none;"
.infoContainer
%p Info text
@jhammann
jhammann / store_page_state.js
Last active September 19, 2025 16:18
Save the current page state into your browser's local storage after you edited it's content with 'contenteditable'.
$(function(){
// this line isn't really necessary here but you have to append this attribute to the element you want the html stored of.
$("#wrapper").attr("contenteditable", "true")
var content = document.getElementById('wrapper');
// save the page's state after you're done with editing and clicked outside the content
$(content).blur(function() {
localStorage.setItem('page_html', this.innerHTML);
@jhammann
jhammann / check_localstorage.js
Created July 15, 2013 15:06
Paste this javascript line into Chrome's console to check how much size your current local storage takes up.
// paste this in your chrome's console
for(var x in localStorage)console.log(x+"="+((localStorage[x].length * 2)/1024/1024).toFixed(2)+" MB");