This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
require 'fileutils' | |
def analyze | |
Dir.glob("public/dist/**/*.{js,css}").reduce({}) do |hash, filename| | |
filename =~ /public\/dist\/([^-]*)(-.{10})?\.(.*)/ | |
name = "#{$1}.#{$3}" | |
# puts name | |
hash[name] = File.new(filename).size |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
signups = cuco_session.course_signups.includes(:course_role, :course).where(person: family.people) | |
count = signups.where(person_id: person.id).joins(:course).where(courses: { period_id: period.id }).count | |
## | |
x = cuco_session.course_signups | |
y = x.includes(:course_role, :course) | |
signups = y.where(person: family.people) | |
a = signups.where(person_id: person.id) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// What should we call the things under each day? | |
// Its kinda like a recurring event but not quite | |
// "WeeklyScheduleEventThingy"? We can do better! | |
// http://delorean/schedules?staff_member_uid=asdfasdfasfd | |
// create, update, index, show | |
{ | |
"schedule": { | |
"start_date": "2016-01-01", |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-(void)someBigMethod { | |
// create a screenshot | |
CALayer * screenLayer = [[[[[UIApplication sharedApplication] keyWindow] rootViewController] view] layer]; | |
CGFloat const shotScale = ([[UIScreen mainScreen] scale] / 2.0); | |
UIGraphicsBeginImageContextWithOptions(screenLayer.bounds.size, YES, shotScale); | |
[screenLayer renderInContext:UIGraphicsGetCurrentContext()]; | |
UIImage * screenshot = UIGraphicsGetImageFromCurrentImageContext(); | |
UIGraphicsEndImageContext(); | |
// put the screenshot in a layer |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class UIView | |
def top | |
frame.origin.y | |
end | |
def left | |
frame.origin.x | |
end | |
def height | |
frame.size.height | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
% A brute force algorithm to solve the Surpassing Problem posed by Martin Rem in 1988 | |
% | |
% By definition, a surpasser of an element of an array is a greater element to the right, | |
% so x[j] is a surpasser of x[i] if i < j and x[i] < x[j]. The surpasser count of an element | |
% is the number of its surpassers. For example, the surpasser count of the string GENERATING | |
% are given by | |
% | |
% G E N E R A T I N G | |
% 5 6 2 5 1 4 0 I 0 0 | |
% The maximum surpasser count is 6. The first occurrence of the letter E has six surpassers, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Ruby Implementation of lazy array for memoized fib | |
# Inspired by Pat Shaughnessy's talk at http://bostonrb.org/presentations/month/March-2013 | |
# Define a LazyArray class that caches results | |
# The cache is valid as long as we use it functionally meaning that | |
# the fn has no side effects and always returns the same output for the same input | |
class LazyArray | |
def initialize(fn) | |
@fn = fn | |
@cache = {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def fib(x) | |
puts "fib(#{x})" | |
return 1 if [0,1].include? x | |
return fib(x-1) + fib(x-2) | |
end | |
cache = (0..Float::INFINITY).lazy.map {|x| fib(x) } | |
class << cache | |
def [](n) | |
take(n).force.last |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /usr/bin/env ruby | |
Dir['/srv/*/current'].each do |dir| | |
if File.exist?("#{dir}/Gemfile.lock") | |
puts dir | |
puts `cd #{dir} && bundle-audit` | |
end | |
end | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# ============================= | |
# Test case showing what we expect to happen | |
a1 = 'z' | |
b1 = 'z' | |
a = [a1] | |
b = [b1] | |
# array '-' https://github.com/ruby/ruby/blob/trunk/array.c#L3806 | |
# It compares elements using their #hash and #eql? methods for efficiency. |
NewerOlder