Skip to content

Instantly share code, notes, and snippets.

View benmj's full-sized avatar
:shipit:

Ben Jacobs benmj

:shipit:
View GitHub Profile
@benmj
benmj / geocoder-service.js
Created August 29, 2013 16:38
An AngularJS Service for intelligently geocoding addresses using Google's API. Makes use of localStorage (via the ngStorage package) to avoid unnecessary trips to the server. Queries Google's API synchronously to avoid `google.maps.GeocoderStatus.OVER_QUERY_LIMIT`
/*global angular: true, google: true, _ : true */
'use strict';
angular.module('geocoder', ['ngStorage']).factory('Geocoder', function ($localStorage, $q, $timeout) {
var locations = $localStorage.locations ? JSON.parse($localStorage.locations) : {};
var queue = [];
// Amount of time (in milliseconds) to pause between each trip to the
#!/usr/bin/env python
# -*- coding: utf8 -*-
import oauth2 as oauth
import urlparse
import os
import urllib
import sys
import json
from pprint import pprint
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.9.1.js"></script>
<script type="text/javascript" src="http://code.jquery.com/ui/1.10.3/jquery-ui.js"></script>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/angularjs/1.0.7/angular.min.js"></script>
<link rel="stylesheet" type="text/css" href="http://code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css">
<title></title>
</head>
@benmj
benmj / hello.txt
Created October 30, 2013 01:14
a text file
Hello, world!
body {
color: red;
font-weight: bold;
}
@benmj
benmj / basic-style-snoop.js
Created September 30, 2013 21:37
from third party javascript
function getStyle (node, property, camel) {
var value;
if (window.getComputedStyle) {
value = document.defaultView.getComputedStyle(node, null)
.getPropertyValue(property);
} else if (node.currentStyle) {
// IE fallback
value = node.currentStyle[property] ?
node.currentStyle[property] :
@benmj
benmj / ratios.less
Created September 9, 2013 21:14
An easy way to maintain a specific ratio on fluid containers using only CSS.
/**
* Ratios.less
*
* Ben Jacobs <ben.jacobs@buildium.com> 2013/09/09
*
* Inspired by a [blog post][1] on maintaing aspect ratio of fluid content
* using only CSS.
*
* [1]: http://ansciath.tumblr.com/post/7347495869/css-aspect-ratio by ansciath
*/
<script type="text/ng-template" id="one.html">
<div>This is first template</div>
</script>
<script type="text/ng-template" id="two.html">
<div>This is second template</div>
</script>
@benmj
benmj / directive.js
Created April 22, 2013 15:52
This works fine in development (Grunt server), but when I deploy it there's a javascript error: "Error: No controller: ngController" However, the controller (passed in as the forth parameter to `link`) works: inside the directive body the functions on the controller can be accessed. I'm happy that it works, but I wonder... why?
angular.module('portal', []).directive('ordersPendingControls', function ($compile) {
return {
scope: {
ordersPendingControls: '='
},
require: "^ngController",
replace: true,
template: '<div>' +
' <button class="btn btn-small" ng-click="editClicked()" ng-disabled="editDisabled" title="Edit this request"><i class="icon-pencil"></i></button>' +
' <button class="btn btn-small" ng-click="deleteClicked()" ng-disabled="deleteDisabled" title="Delete this request"><i class="icon-remove-circle icon-remove"></i></button>' +
<h1>Alert</h1>
<p>Bootstrap JS</p>
<div class="alert fade in">
<button type="button" class="close" data-dismiss="alert">×</button>
<strong>Holy guacamole!</strong> Best check yo self, you're not looking too good.
</div>
<p></p><a ng-click="alert=true">Open Alert (AngularJS)</a></p>
<div class="alert fade" ng-class="{in:alert}">
<button type="button" class="close" ng-click="alert=false">×</button>