Skip to content

Instantly share code, notes, and snippets.

View sycobuny's full-sized avatar

Stephen Belcher sycobuny

  • Kelly Services, NIH/NIA
  • Baltimore, MD
View GitHub Profile
@sycobuny
sycobuny / factory_method.js
Last active May 13, 2016 17:40
Comparing two potential ways to solve the "attach a 'global' function to my Angular app" question
myApp.factory('queryStringFactory', [function() {
return function(obj) {
var params = []
for (var key in obj) {
params.push(
encodeURIComponent(key) + '=' + encodeURIComponent(obj[key])
)
}
@sycobuny
sycobuny / a_question.md
Last active June 10, 2016 22:32
Puzzling out some left-ambiguous angular style guide recommendations

So, in the IIFE section of the angular styleguide, it suggests using function expressions to encapsulate angular component definitions inside of a function expression in order to keep the logic easy to understand while also keeping the global namespace clear.

And, later in the document, it has a more complete example including putting binding members of a controller at the top of a function defining a component. It shows that, inside of this component's function, more functions are declared.

@sycobuny
sycobuny / a_bit_of_info.md
Last active July 5, 2016 15:06
Calculating a series based on an initial timestamp and a potentially multiple-day-spanning sequence of ordered times

This query is meant to serve as a proof-of-concept for parsing sleep data off of the fitbit API, which returns you a start date, and then a series of times. Given that these data are polled every minute, you can safely assume that, when you cross a date boundary, the next measurement of time will be "smaller" than the last, and we could just break it into two days.

However, in an extreme edge case where either the fitbit is reporting wrong, or someone really is sleeping for more than 24 hours,

@sycobuny
sycobuny / output.txt
Last active January 19, 2017 20:43
A proof-of-concept for a simple string replacement program
Old string: Here's a string with a couple ' in it
New String: Here\'s a string with a couple \' in it
@sycobuny
sycobuny / my_ctrl.constants.js
Created June 29, 2017 18:48
Which way is prettier? (Or "better", if not prettier)
// describe the constants as angular constants, namespaced to the controller that uses them
(function(angular, undefined) {
angular.module('myapp').constant('MyCtrl.API_ENDPOINT', 'https://myserver.com/data.json')
})(angular)
@sycobuny
sycobuny / update.sql
Created October 21, 2023 15:41
Updating Associated Tags for a given Thing in one query.
WITH
thing_id(i) AS (VALUES (123)),
new_tag_list(t) as (
VALUES ('t1', 't2')
),
inserted_tags(tagid, thingid) AS (
INSERT INTO tags_things
(tag_id, thing_id)
SELECT nt.id,
(SELECT id FROM thing_id LIMIT 1)