Skip to content

Instantly share code, notes, and snippets.

@shajith
shajith / ranges.rb
Last active January 13, 2018 09:26 — forked from jacobat/ranges.rb
def ranges(io, max_step = 1)
in_range = false
first = nil
last = nil
io.each_line do |line|
id = line.to_i
if first.nil?
first = id
last = id
@shajith
shajith / ranges.rb
Created January 13, 2018 08:13 — forked from jacobat/ranges.rb
def group_continuous(io)
result = []
range_start = nil
offset = 0
io.each_line do |line|
id = line.to_i
puts "#{id}\t#{range_start}\t#{offset}"
if !range_start.nil? && id == range_start + offset + 1
offset = offset + 1
@shajith
shajith / countCSSRules.js
Created December 5, 2012 01:48 — forked from psebborn/countCSSRules.js
Count the number of rules and selectors for CSS files on the page. Flags up the >4096 threshold that confuses IE
function countCSSRules() {
var results = '',
log = '';
if (!document.styleSheets) {
return;
}
for (var i = 0; i < document.styleSheets.length; i++) {
countSheet(document.styleSheets[i]);
}
function countSheet(sheet) {
@shajith
shajith / pre-commit.rb
Created November 17, 2010 21:26
Some git pre-commit checks in Ruby. Kind of dumb for now. Try it out and fix what's broken plz?
#!/usr/bin/env ruby
class Utils
def self.staged_files(*dirs)
@staged_files ||= {}
@staged_files[dirs.join(' ')] ||= `git diff --cached --name-only #{dirs.join(' ')} | xargs`.chomp
end
end