Skip to content

Instantly share code, notes, and snippets.

View compwron's full-sized avatar
💭
https://github.com/drop-ice/dear-github-2.0

compwron compwron

💭
https://github.com/drop-ice/dear-github-2.0
View GitHub Profile
@compwron
compwron / gist:256a8594c87dbbf98359
Created August 27, 2015 22:10
testing contexts
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
@compwron
compwron / gist:9004950
Created February 14, 2014 17:09
gradlew
@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
@compwron
compwron / gist:0499c61ba441e3e8cb4a
Created July 1, 2014 20:08
vim tmux practice navigation setup generator
class Tvcom
attr_reader :command
attr_accessor :valid
def initialize(foo, valid)
@command = foo
@valid = valid
end
def flip
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}`
@compwron
compwron / gist:eaa59d38c33e86f923ca
Created December 9, 2014 03:49
howto set all input fields from hash in ruby
def initialize(field_data)
field_data.each do |name, value|
instance_variable_set("@#{name}", value)
end
end
# 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]
@compwron
compwron / gist:a64972f2e3c527405923
Created January 9, 2015 19:08
alpha params finder
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
@compwron
compwron / gist:d883710cf84bbd213eed
Last active August 29, 2015 14:13
matching parens
# 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
@compwron
compwron / gist:115a7cf9aaa9d5271e2a
Last active August 29, 2015 14:13
sum2 in n*2
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
@compwron
compwron / gist:65f8a1eedffe9cd2d208
Created January 23, 2015 16:20
max diff in moving subset window
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