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
require 'spec_helper' | |
describe 'testing contexts' do | |
before { p 1 } | |
context 'aa' do | |
before { p 2 } | |
it 'foo' do | |
expect(42).to eq 42 | |
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
@if "%DEBUG%" == "" @echo off | |
@rem ########################################################################## | |
@rem | |
@rem Gradle startup script for Windows | |
@rem | |
@rem ########################################################################## | |
@rem Set local scope for the variables with windows NT shell | |
if "%OS%"=="Windows_NT" setlocal |
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 Tvcom | |
attr_reader :command | |
attr_accessor :valid | |
def initialize(foo, valid) | |
@command = foo | |
@valid = valid | |
end | |
def flip |
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
files = `git ls-files | grep -v vendor`.split("\n") | |
a = files[Random.new.rand(files.size)] | |
p a | |
`open -a "/Applications/Sublime\ Text.app/" #{a}` | |
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 initialize(field_data) | |
field_data.each do |name, value| | |
instance_variable_set("@#{name}", value) | |
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
# You are asked to write a max_slice function which takes as an input an array of integers, and returns the slice with the largest sum of the elements | |
a = [1, 2, 3, 4, 5] | |
b = [1, -2, 6, -4, 5] | |
[1] | |
[1, -2] | |
[1, -2, 6] | |
[-2, 6] |
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
filename = ARGV[0] || 'app/models/transaction.rb' | |
f = File.open(filename, 'rb') | |
c = f.read | |
all = c.split(/\n|,/).map { |i| i.strip.gsub(/[^A-Za-z0-9\s\[\]\._\(\)]/, '') }.reject(&:empty?) | |
# too many false positives | |
DEFAULT = 'aaa --- DEFAULT --- ' | |
alph_list = [DEFAULT] | |
all.each do |line| | |
if [alph_list.last, line].sort.last == line # this line is after everything in alph list alphabetically |
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
# Task: write a function to determine if a string is | |
# 'balanced'. Balanced means that opening and closing | |
# brackets match each other in the proper order. Other | |
# characters are possible and should be handled. The | |
# possible characters for balancing are {}, (), and [] | |
# Example Input: | |
# '{}' -> True | |
# '{[]}' -> True |
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 sum2 choices, result | |
arrays = [] | |
choices.each_with_index {|i, index| | |
choices.each_with_index {|j, index2| | |
break if index == index2 | |
arrays << [i, j] if i + j == result | |
} | |
} | |
arrays | |
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
def max_devi(choices, setlength) # v, d | |
largest_diff = 0 | |
largest_diff_subset = [] | |
(0..choices.length - setlength).each do|i| | |
subset = choices[i..i + setlength] | |
diff = subset.max - subset.min | |
if diff > largest_diff | |
largest_diff_subset = subset | |
largest_diff = diff | |
end |
OlderNewer