Skip to content

Instantly share code, notes, and snippets.

View shaundon's full-sized avatar

Shaun Donnelly shaundon

View GitHub Profile
@shaundon
shaundon / json_to_csv.js
Created September 19, 2013 15:27
JSON to CSV converter.
function JsonToCsv(json) {
var csv = '';
// Begin with the header row, using
// the keys as headings.
for (var key in json[0]) {
csv += key + ',';
}
@shaundon
shaundon / gist:7805684
Created December 5, 2013 14:09
A loading indicator that jumps down from the top of the page when it has the class 'visible'.
#global-loading {
background: lighten(#ff0, 35%);
@include borderBottomRadius(3px);
@include boxShadow((0 0 5px rgba(#000, .5)));
color: #333;
color: rgba(#000, .4);
font-size: 24px;
font-weight: bold;
left: 50%;
height: 70px;
@shaundon
shaundon / server.rb
Created December 6, 2013 09:37
A very simple Sinatra server. Used for serving pages locally. I mainly use this for hosting functional mockups on my system.
require 'sinatra'
set :port, 4567
set :public_folder, File.dirname(__FILE__) + '/'
get '/' do
File.read('index.html')
end
@shaundon
shaundon / pendulum.css
Last active December 30, 2015 11:19
A CSS animation to swing like a pendulum. Slows slightly at the apexes to simulate physics.
@keyframes pendulum {
0%, 100% { transform: rotate(-5deg); }
10%, 90% { transform: rotate(0deg); }
40%, 60% { transform: rotate(90deg) }
50% { transform: rotate(95deg); }
}
// Rest of code omitted.
.directive('myDirective', function () {
return {
restrict : 'E',
templateUrl : '/templates/directives/mydirective.html',
replace : true
}
})
@shaundon
shaundon / webpage.rb
Created March 6, 2014 12:34
Takes a POST request, and opens a webpage.
require 'sinatra'
require 'launchy'
set :port, 7428
post '/webpage' do
begin
Launchy.open(params[:url])
rescue
print 'Failed :('
/*
Call start() on console to run program.
May be a little rough around the edges, I'm trying to remember the
jQuery API from memory as my home internet's too slow to Google stuff.
Oh and it requires jQuery, because everything requires jQuery!
*/
function start() {
@shaundon
shaundon / pascals-triangle.js
Created June 20, 2014 08:59
Creates a 2D array that contains a pascal's triangle.
function pascal(rows) {
var pascalsTriangle = [];
for (var row=1; row<=rows; row++) {
var rowResults = [];
if (pascalsTriangle[row-2]) {
var aboveRow = pascalsTriangle[row-2];
@shaundon
shaundon / jasmine_throw_error_test.js
Created January 22, 2015 13:24
How to run a Jasmine test that throws an error
expect(function() {
// Call the code here.
}).toThrow(new Error('some error'));
@shaundon
shaundon / deep_omit.js
Last active August 29, 2015 14:16
Like underscore's omit function, but works deeply. Works on both objects and arrays. Requires underscore.
var deepOmit = function(input, propertyToRemove) {
var output = input;
if (_.isArray(input)) {
output = [];
_.each(input, function(arrayItem) {
output.push(deepOmit(arrayItem, propertyToRemove));
});
}
else if (_.isObject(input)) {
output = {};