Skip to content

Instantly share code, notes, and snippets.

View smithcommajoseph's full-sized avatar

Joseph (Jos) Smith smithcommajoseph

View GitHub Profile
@smithcommajoseph
smithcommajoseph / temperatureCircle.py
Created August 3, 2017 02:41 — forked from anttilipp/temperatureCircle.py
Code to reproduce the "Temperature Circle" visualization.
#
# Hi all,
# this is the Python code I used to make the visualization "Temperature circle"
# (https://twitter.com/anttilip/status/892318734244884480).
# Please be aware that originally I wrote this for my tests only so the
# code was not ment to be published and is a mess and has no comments.
# Feel free to improve, modify, do whatever you want with it. If you decide
# to use the code, make an improved version of it, or it is useful for you
# in some another way I would be happy to know about it. You can contact me
# for example in Twitter (@anttilip). Unchecked demo data (no quarantees)
@smithcommajoseph
smithcommajoseph / svgAnchor.js
Last active August 29, 2015 14:05
a hack 'n slash svg solution
var $el = $('.'+element.attr('class')),
anchors = $el.find('.navbar-right');
// this is a symptom of the SVG api combined w/ bootstrap's plugin,
// recommending swapping bootstrap w/ a custom directive and/or using an ng-click
// on the affected elements
anchors.on('click', function(e) {
var target = $(e.target),
actualTarget;
if (typeof target[0].correspondingUseElement === 'undefined') { return; }
@smithcommajoseph
smithcommajoseph / emberDataBorked.js
Last active August 29, 2015 14:05
nonworking ember data example with relationships
// lookup the store
store = OC2.__container__.lookup('store:main');
// add a serializer to handle our embedded records
// ...either I'm getting this wrong or this is a bug,
// as I can't get this part to work
OC2.ColorSerializer = DS.ActiveModelSerializer.extend(DS.EmbeddedRecordsMixin, {
attrs: {
foos: {embedded: 'always'}
}
@smithcommajoseph
smithcommajoseph / emberDataWorking.js
Created August 26, 2014 15:32
Ember data working sideloaded data example
// lookup the store
store = OC2.__container__.lookup('store:main')
// Models
OC2.Color = DS.Model.extend({
color: DS.attr(),
foos: DS.hasMany('foo'),
colors: DS.hasMany('color')
});
Initializing
Command-line options: --verbose
Reading "Gruntfile.js" Gruntfile...OK
Registering Gruntfile tasks.
Registering "grunt-contrib-copy" local Npm module tasks.
Reading /Users/joseph.smith/Sites/testYo/node_modules/grunt-contrib-copy/package.json...OK
Parsing /Users/joseph.smith/Sites/testYo/node_modules/grunt-contrib-copy/package.json...OK
1.0.4
/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/local/git/bin:/usr/local/munki
darwin { http_parser: '1.0',
node: '0.10.20',
v8: '3.14.5.9',
ares: '1.9.0-DEV',
uv: '0.10.17',
zlib: '1.2.3',
modules: '11',
openssl: '1.0.1e' }
// Generated on 2013-10-02 using generator-angular 0.4.0
'use strict';
var LIVERELOAD_PORT = 35729;
var lrSnippet = require('connect-livereload')({ port: LIVERELOAD_PORT });
var mountFolder = function (connect, dir) {
return connect.static(require('path').resolve(dir));
};
// # Globbing
// for performance reasons we're only matching one level down:
if (typeof Math.factorial === "undefined") {
Math.factorial = function factorial (n) {
if (n == 0 || n == 1)
return 1;
if (Math.factorial.f[n] > 0)
return Math.factorial.f[n];
else
return Math.factorial.f[n] = factorial(n-1) * n;
};
@smithcommajoseph
smithcommajoseph / ninety9beers.js
Created September 12, 2013 17:20
a quick demo of how to code 99 beers on the wall in js
(function(){
var arr = [],
START_COUNT = 99;
TPL = '%count bottles of beer on the wall, %count bottles of beer, take 1 down, pass it around, %nextCount bottles of beer on the wall\r\n';
function init () {
for (var i = START_COUNT; i > 0; i--) {
arr.push(hydrate({count: i, nextCount: i-1}));
}
@smithcommajoseph
smithcommajoseph / timeparser.jison
Created September 9, 2013 20:54
Jison version of PragProg's (the book) timerparser from chapt 2 exercise 7
/* lexical grammar */
%lex
%%
\s+ /* skip whitespace */
([0-9]) return 'DIGIT'
"am" return 'AM'
"pm" return 'PM'
":" return ':'
<<EOF>> return 'EOF'