Skip to content

Instantly share code, notes, and snippets.

@mapsam
mapsam / site.js
Last active August 29, 2015 13:57
using tabletop.js for spreadsheet access
// tabletop.js is linked above
function init() {
var json = []; //prented this is a geojson and not just an array
Tabletop.init({
key: '0AkE-VGwUGzsSdHRjTmtNMXhONjYxQUxnOV9SajY4VkE',
callback: function(data, tabletop) {
var entries = [];
@mapsam
mapsam / getajax.js
Created April 15, 2014 21:04
GET ajax
function init() {
var url = 'http://api.example.com/stuffs...'
$.ajax({
type: "GET",
dataType: "jsonp",
cache: false,
url: url,
success: function(data) {
console.log(data);
},
@mapsam
mapsam / serialize.js
Created April 23, 2014 22:41
jQuery form serialization
$(document).ready(function(){
$('form').submit(function(event){
var json = JSON.stringify($('form').serializeObject());
$('#result').text(json);
return false;
});
$.fn.serializeObject = function() {
var geojson = {};
geojson['type'] = 'FeatureCollection';
@mapsam
mapsam / site.js
Created May 9, 2014 17:46
jquery open/close toggle stuff
$(document).ready(function($){
$('#open').click(function(){
$('#element').toggle(300).addClass('active');
});
$('#close').click(function(){
if($('#element').hasClass('active')) {
$('#element').toggle(300).removeClass('active');
}
});
});
@mapsam
mapsam / scroll.js
Last active August 29, 2015 14:01
scroll on anchor tag click within page
var height = $('header').height(); // element to offset scroll with (i.e. your navbar if it is fixed)
$('a[href*=#]').click(function() {
if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'')
&& location.hostname == this.hostname) {
var $target = $(this.hash);
$target = $target.length && $target
|| $('[name=' + this.hash.slice(1) +']');
if ($target.length) {
var targetOffset = ($target.offset().top)-height; //offset from top based on element - this isn't required
$('html,body')
@mapsam
mapsam / jsonp.js
Created May 28, 2014 20:51
jQuery ajax with jsonp to census.gov
$.ajax({
type: "GET",
dataType: "jsonp",
contentType: "application/json",
url: 'http://geocoding.geo.census.gov/geocoder/locations/onelineaddress?address=131+Riverlawn+Ave%2C+Watertown%2C+53094&benchmark=9&format=jsonp',
success: function(data) {
console.log(data)
},
error: function(xhr, ajaxOptions, thrownError) {
console.log(xhr.status, thrownError);
@mapsam
mapsam / loop.php
Last active August 29, 2015 14:04
wordpress custom taxonomy list of terms and posts
<?php
// using a specified custom taxonomy slug
// find all taxonomy terms (categories) and
// the associated posts
$tax = 'TAXONOMY-SLUG';
echo '<ul>';
$terms = get_terms($tax);
foreach($terms as $term) {
echo '<li>'.$term->name;
@mapsam
mapsam / getID.php
Last active August 29, 2015 14:06
YouTube shortcode embed
<?php // get youtube ID function
function get_youtube_id($url) {
$query_string = array();
parse_str(parse_url($url, PHP_URL_QUERY), $query_string);
$id = $query_string["v"];
return $id;
}
@mapsam
mapsam / parallax.css
Created September 19, 2014 17:27
simple parallax
#parallax-wrap {
height: 400px; /* anything you want/need */
width: 100%;
position: relative;
display: block;
}
.parallax {
position:absolute;
width:100%;
height:100%;