Skip to content

Instantly share code, notes, and snippets.

Avatar

Benjamin Charity benjamincharity

View GitHub Profile
View SassMeister-input-HTML.html
<div class="window">
<section></section>
<aside></aside>
</div>
@benjamincharity
benjamincharity / htmlEntities.js
Created Feb 14, 2014
Strip html entities with Javascript
View htmlEntities.js
// http://css-tricks.com/snippets/javascript/htmlentities-for-javascript/
function htmlEntities(str) {
return String(str).replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/"/g, '&quot;');
}
@benjamincharity
benjamincharity / filter.sentanceCase.coffee
Created Feb 28, 2014
Sentance case filter for Angular. Solution below requires Underscore.js
View filter.sentanceCase.coffee
myModule.filter "sentence_case", ->
_.memoize (x) ->
return unless angular.isString(x)
x = x.toLowerCase()
capitalize = (str) ->
str += ''
return str.charAt(0).toUpperCase() + str.slice(1)
fmt = (y) ->
capitalized = capitalize($.trim(y))
@benjamincharity
benjamincharity / spotijay_error
Created Jan 27, 2015
An error seen while getting Spotijay up and running.
View spotijay_error
/Users/bc/Dropbox/Projects/open-source/Spotijay/node_modules/libspotify/node_modules/bindings/bindings.js:83
throw e
^
Error: dlopen(/Users/bc/Dropbox/Projects/open-source/Spotijay/node_modules/libspotify/build/Release/spotify.node, 1): Library not loaded: /usr/local/opt/libspotify/lib/libspotify
Referenced from: /Users/bc/Dropbox/Projects/open-source/Spotijay/node_modules/libspotify/build/Release/spotify.node
Reason: image not found
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Module.require (module.js:364:17)
@benjamincharity
benjamincharity / validation.rule.js
Created Mar 5, 2015
Validation rules for the Angular Validation library - https://github.com/huei90/angular-validation/ .
View validation.rule.js
/* jshint regexdash: false */
(function() {
angular.module('validation.rule', ['validation'])
.config(['$validationProvider', function($validationProvider) {
var expression = {
required: function(value) {
return !!value;
},
url: /((([A-Za-z]{3,9}:(?:\/\/)?)(?:[-;:&=\+\$,\w]+@)?[A-Za-z0-9.-]+|(?:www.|[-;:&=\+\$,\w]+@)[A-Za-z0-9.-]+)((?:\/[\+~%\/.\w-_]*)?\??(?:[-\+=&;%@.\w_]*)#?(?:[\w]*))?)/,
@benjamincharity
benjamincharity / iosContactTemplate.js
Created May 8, 2015
JSON generator template for iOS contact creation
View iosContactTemplate.js
[
"{{repeat(100, 100)}}",
{
"fn":{
"name":"{{firstName()}} {{surname()}}"
},
"n":{
"families":"{{surname()}}",
"givens":"{{firstName()}}"
},
@benjamincharity
benjamincharity / centsToDollars.js
Created May 19, 2015
Convert cents to dollars.
View centsToDollars.js
angular.module('MyModule')
.filter('dollars', function() {
return function(input) {
return '$' + parseInt(input, 10) / 100;
};
});
@benjamincharity
benjamincharity / manageBucket.json
Created May 20, 2015
List all Amazon S3 buckets and allow management of a single bucket.
View manageBucket.json
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": "s3:*",
"Resource": [
"arn:aws:s3:::my.bucket.com",
"arn:aws:s3:::my.bucket.com/*"
]
@benjamincharity
benjamincharity / splitStringAtFirstSpace.regex
Created May 21, 2015
Split a string at the first space.
View splitStringAtFirstSpace.regex
var myString = 'foo bar baz';
var firstWord = myString.substr( 0, myString.indexOf(' ') ); // 'foo'
var stringRemainder = myString.substr( myString.indexOf(' ') + 1 ); // 'bar baz'
@benjamincharity
benjamincharity / cleanNumbers.regex
Created May 21, 2015
Strip all non-digit characters.
View cleanNumbers.regex
newValue = oldValue.replace(/[^0-9]/g, "");