Skip to content

Instantly share code, notes, and snippets.

View rintaun's full-sized avatar

Matthew Lanigan rintaun

View GitHub Profile
@rintaun
rintaun / story.rb
Created September 30, 2018 17:25
Prepared query for counting the subset of tags for stories with the given tags
class Story < Sequel::Model
STORY_COUNT_BY_TAGS =
select { [tag, count(tag)] }
.from(
select { unnest(tags).as(tag) }
.from(:stories)
.where(
Sequel
.pg_array(:tags)
.contains(Sequel.cast(:$filter, :'text[]').pg_array)
@rintaun
rintaun / mixin_test.rb
Created July 29, 2018 14:03
YARD handles inheritance very strangely. Enabling --embed-mixins changes what is shown as included/extended, but with or without, the output is incorrect.
# frozen_string_literal: true
# Test mixin
#
# {.mixin_class_attribute} and {.mixin_class_method} _never_ end up accessible
# in the inheriting class.
module TestMixin
class << self
attr_reader :mixin_class_attribute
def mixin_class_method; end
@rintaun
rintaun / Gemfile
Created July 14, 2018 03:55
The cyclic dependency in this test generates a unique constraint violation due to how aliases are assigned to track which entries have already been inserted to the database.
source 'https://rubygems.org'
gem 'sequel'
gem 'fixture_dependencies'
gem 'sqlite3'
@rintaun
rintaun / gpa.sql
Last active August 29, 2015 14:15
Simple system to track grades and easily calculate GPA (cumulative, specific year, or specific term)
CREATE TABLE classes (
id SERIAL PRIMARY KEY,
name TEXT NOT NULL,
year INTEGER NOT NULL,
term INTEGER NOT NULL,
grade DECIMAL NOT NULL,
credits INTEGER NOT NULL
);
CREATE OR REPLACE FUNCTION gpa() RETURNS DECIMAL
@rintaun
rintaun / ashton_test_1.rb
Last active August 29, 2015 14:06
Ashton texture rendering interacts strangely with... well, everything.
require 'gosu'
require 'ashton'
=begin
This test is basic proof that rendering one texture interacts with rendering others.
This will render a black screen, despite `secondary_buffer` never being drawn.
If you alter the order of the `primary_buffer` and `secondary_buffer` renders in #update,
then you will see the 250x250 red square render at 0,0 as expected.
=end
module SomeMethodsPlease
def self.included(klass)
klass.instance_eval do
alias_method :old_initialize, :initialize
def initialize
p "the new one"
old_initialize
end
end
end
rintaun@valhalla:~/gittest$ git init
Initialized empty Git repository in /home/rintaun/gittest/.git/
rintaun@valhalla:~/gittest$ touch first
rintaun@valhalla:~/gittest$ git add first
rintaun@valhalla:~/gittest$ git commit -m "first"
[master (root-commit) 0f60b13] first
0 files changed
create mode 100644 first

So, I have noticed a pattern that has appeared in how I develop directives, and I'm wondering if there isn't a better way to accomplish the same thing. Specifically, I find that in a directive with its own scope (either isolated or inherited), it is sometimes useful to add utility methods to the parent scope. For example:

directive('hello', function() {
    return {
        restrict: 'A',
        scope: {},
        link: function(scope, elem, attrs) {
            scope.$parent.alert = function() {
 var who = attrs.hello || 'World'
@rintaun
rintaun / asdf.rb
Last active December 17, 2015 05:29
class User < Sequel::Model
one_to_many :memberships
many_to_many :teams, :join_table => :memberships
end
class Membership < Sequel::Model
many_to_one :user
many_to_one :team
end
class User < Sequel::Model
one_to_many :memberships
many_to_many :teams, :join_table => :memberships
end
class Membership < Sequel::Model
one_to_many :users
one_to_many :teams
end