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 / 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
*/
@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
<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>
@benmj
benmj / transactions-overview.html
Created February 28, 2013 22:26
ng-repeat on selection
<h2>{{ transaction.Title || "Transactions" }}</h2>
<label for="selectedYear">View transactions from: </label>
<select name="selectedYear" ng-model="selectedYear">
<option ng-repeat="year in years">{{year}}</option>
</select>
@benmj
benmj / google-table-directive.js
Created February 27, 2013 23:33
An AngularJS Directive for creating a table using the Google Visualization API
/*
I'm converting an existing web-app to angular. We made extensive use of the
Google Visualization library in the past. It's a powerful, although
complicated API, so I was anxious to get it wrapped up in angular. This
populates a table with data returned from a custome service 'Account'
*/
'use strict';
/* Directives */
<?php
foreach ($_FILES as $file) {
switch($file['error']) {
case UPLOAD_ERR_INI_SIZE:
error_log("The uploaded file exceeds the upload_max_filesize directive in php.ini. : " . $file['name']);
break;
case UPLOAD_ERR_FORM_SIZE:
error_log("The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form. " . $file['name']);
@benmj
benmj / bookmark.txt
Created February 1, 2013 06:11
Where to pick up
http://symfony.com/doc/current/book/doctrine.html#saving-related-entities
#!/usr/bin/env python
# -*- coding: utf8 -*-
import oauth2 as oauth
import urlparse
import os
import urllib
import sys
import json
from pprint import pprint