Skip to content

Instantly share code, notes, and snippets.

View ozydingo's full-sized avatar

Andrew H Schwartz ozydingo

View GitHub Profile
@ozydingo
ozydingo / keyscroller.js
Created February 2, 2019 15:11
a/z key scrolling to scroll-disabled web content
function KeyPress(e) {
var evtobj = window.event? event : e
if (evtobj.keyCode == 90) {
window.scrollBy(0, 100)
}
if (evtobj.keyCode == 65) {
window.scrollBy(0, -100)
}
}
@ozydingo
ozydingo / .bashrc
Last active February 2, 2019 15:21
Git Branch Prompt
source colors.sh
bash_colors
source gitbranch.sh
PS1='[\[$(git_branch_color)\]$(parse_git_branch)\[${NORMAL}\]] '"$PS1"
@ozydingo
ozydingo / graph2.js
Last active February 3, 2018 23:09
Barebones js x,y graph using canvas element
function Graph2(canvas) {
if (canvas.tagName !== 'CANVAS') { throw 'Graph2 requires a canvas element'; }
this.canvas = canvas;
this.cursor = canvas.getContext("2d");
this.axes = {
display: false,
xlim: [-1, 1],
ylim: [-1, 1],
}
@ozydingo
ozydingo / current-dir-in-iterm-tab-title.sh
Last active June 12, 2018 18:54 — forked from phette23/current-dir-in-iterm-tab-title.sh
Set the iTerm tab title to the current directory, not full path.
# Ensure that you have your iTerm configured to allow the shell to modify the window / tab title.
# In iTerm 3.1.2 this is a checkbox located in Settings > Profile > Terminal: "Terminal may set tab/window title"
# Then, put this in your .bash_profile
if [ $ITERM_SESSION_ID ]; then
export PROMPT_COMMAND='echo -ne "\033];${PWD##*/}\007"; ':"$PROMPT_COMMAND";
fi
# Piece-by-Piece Explanation:
# the if condition makes sure we only screw with $PROMPT_COMMAND if we're in an iTerm environment
# iTerm happens to give each session a unique $ITERM_SESSION_ID we can use, $ITERM_PROFILE is an option too
--
Introduction:
This coding challenge is designed for you to show off your skills to the 3Play Media Developer team. You
should have the following challenge completed by the time you come in for your in-person interview so we
can take a look at it together. While all of the basic requirements of this project should be met, you're
encouraged to make this project your own and implement any additional features that you see fit.
Feel free to ask whatever questions, use whatever resources and provide whatever documentation
you'd like during the completion of this project.
@ozydingo
ozydingo / caputre_stdout.rb
Created June 9, 2016 08:21
Ruby class for capturing puts / stdout buffer
require 'stringio'
class CaptureStdout
def initialize(&blk)
@handler = blk
end
def capture
StringIO.open do |io|
stash = $stdout
@ozydingo
ozydingo / caputre_stdout.rb
Last active June 9, 2016 08:37
Ruby class for capturing puts / stdout buffer
require 'stringio'
class CaptureStdout
def initialize(&blk)
@handler = blk
end
def capture
StringIO.open do |io|
stash = $stdout
@ozydingo
ozydingo / BUG: default_scope has_one through self-referential
Created April 17, 2016 11:43
Code to reproduce bug with a has_one :through referential relationship where both models have a default scope
# Foo has_one :bar, Bar belongs_to :foo
# Foo has_one parent_foo and has_many child_foos
# Bar has_one parent_foo through :foo
# Bar has_one parent_bar through :parent_foo
#
# The parent_bar association incorrectly applies values into the SQL query
# You can see this in the query generated from b1.parent_bar in the code below: notice there are 3 "?"s and 2 node values.
# SELECT "bars".* FROM "bars" INNER JOIN "foos" ON "bars"."foo_id" = "foos"."id" INNER JOIN "foo_relationships" ON "foos"."id" = "foo_relationships"."parent_foo_id" INNER JOIN "foos" "foos_parent_bar_join" ON "foo_relationships"."child_foo_id" = "foos_parent_bar_join"."id" WHERE "bars"."deleted" = ? AND "foos"."deleted" = ? AND "foos_parent_bar_join"."id" = ? LIMIT 1 [["deleted", "f"], ["id", 2]
#
# This is more noticeable when using MySQL, as it is less forgiving of missing nodes: notice that the id of '2' is being applied to `foos`.`deleted`, and final value for `foos_parent_bar_join`.`id` in the query string is simply missing
@ozydingo
ozydingo / application.rb
Created April 5, 2016 16:31
Intercept routing errors when consider_all_requests_local = true, only show debugging info is user is logger in
[...]
if Rails.env == "staging"
require "#{Rails.root}/lib/staging_exception_handler.rb"
config.middleware.use StagingExceptionHandler
end
[...]
@ozydingo
ozydingo / active_record_extension.rb
Last active June 16, 2021 22:47
ActiveRecord left join
module ActiveRecordExtension
extend ActiveSupport::Concern
module ClassMethods
# Simple left join taking advantage of existing Rails & Arel code
def left_joins(*args)
inner_joins = self.joins(*args).arel.join_sources
left_joins = inner_joins.map do |join|
Arel::Nodes::OuterJoin.new(join.left, join.right)
end