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 / 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)
@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 / 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 / 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 / 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 / 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 / output.txt
Created January 16, 2016 23:22
tmux control mode output
~$ tmux -CC
** tmux mode started **
Command Menu
----------------------------
esc Detach cleanly.
X Force-quit tmux mode.
L Toggle logging.
C Run tmux command.
Detached
@sycobuny
sycobuny / ansible.cfg
Created November 12, 2015 22:46
Silly example ansible dynamic inventory
[defaults]
inventory = ./inventory.pl
@sycobuny
sycobuny / pg_isolation.rb
Last active August 27, 2015 14:21
Rack middleware to (theoretically) "isolate" certain requests in a read-only transaction
# "Isolates" Rack operations via Sequel/PostgreSQL into read-only transactions
#
# @note (see PGIsolation#shadow_tables!)
class PGIsolation
attr_reader :app, :db_method, :shadow_tables, :setup, :teardown,
:isolation_check
# A template for creating multiple temporary tables in sequence
#
# Due to the +LIKE+ clause (and <tt>INCLUDING DEFAULTS</tt>), these tables
@sycobuny
sycobuny / README.md
Last active March 17, 2016 07:03
A problem I'm encountering with pgTAP (http://pgtap.org/)

The Problem

I'm hoping to test a function that I will eventually use in a DOMAIN to verify that any given JSONB object adheres to a certain loose set of constraints (other JSONB types will be built on constraints specified in this DOMAIN).

As the DOMAIN will already fail anything that doesn't pass the function, I did not write the function to raise exceptions, but rather to raise warnings,