https://gyazo.com/eb5c5741b6a9a16c692170a41a49c858.png

| /* A modified default Jekyll theme | |
| /* | |
| /* Improvements include: | |
| /* | |
| /* 1. Responsive Template: Added media-queries so that it works well | |
| /* on a wide-range of screens. | |
| /* | |
| The MIT License (MIT) | |
| def numberOfHoursBack = 7*24 | |
| def totalBuildTime = | |
| Jenkins.instance.getItems(Job.class).collect { job -> | |
| job.getBuilds().byTimestamp(System.currentTimeMillis()-numberOfHoursBack*60*60*1000, System.currentTimeMillis()) | |
| } | |
| .flatten() | |
| .collect { build -> build.getDuration() } | |
| .sum() |
| #!/usr/bin/env python | |
| """ Sends Jenkins build duration statistics to Graphite. """ | |
| import requests | |
| import json | |
| from graphite import Graphite # This is our closed-source library but you get the idea. | |
| JENKINS_URL='http://jenkins' | |
| GRAPHITE_HOST='10.x.x.x' | |
| GRAPHITE_PREFIX='jenkins.main.build_time.' |
| class Address | |
| def initialize address, display_name, domain | |
| @address = address | |
| @display_name = display_name | |
| @domain = domain | |
| end | |
| attr_reader :address, :display_name, :domain | |
| def self.from_header h # returns an Array of Addresses |
| # Benchmarking answers to http://stackoverflow.com/questions/9333952/in-ruby-how-to-make-the-string-include-method-ignore-case/9334066 | |
| # http://www.gutenberg.org/cache/epub/1661/pg1661.txt | |
| strings = IO.read('sherlock.txt').scan(/\w+/) # 109,222 words | |
| known = 500.times.map do | |
| strings.sample.downcase.chars.map{ |c| rand<0.5 ? c.upcase : c }.join | |
| end | |
| words = known.flat_map{ |s| [s, s+"-"] } # \w does not include - |
| # Put this code in lib/validators/json_validator.rb | |
| # Usage in your model: | |
| # validates :json_attribute, presence: true, json: true | |
| # | |
| # To have a detailed error use something like: | |
| # validates :json_attribute, presence: true, json: {message: :some_i18n_key} | |
| # In your yaml use: | |
| # some_i18n_key: "detailed exception message: %{exception_message}" | |
| class JsonValidator < ActiveModel::EachValidator |
| # ActiveRecord::Base#dup and ActiveRecord::Base#clone semantics have changed to closer match normal Ruby dup and clone semantics. | |
| # Calling ActiveRecord::Base#clone will result in a shallow copy of the record, including copying the frozen state. No callbacks will be called. | |
| # Calling ActiveRecord::Base#dup will duplicate the record, including calling after initialize hooks. Frozen state will not be copied, and all associations will be cleared. A duped record will return true for new_record?, have a nil id field, and is saveable. |
| require "csv" | |
| def csv_headers | |
| ["Your", "Headers", "Here"] | |
| end | |
| files = Dir["file_names_*.csv"].sort_by { |f| "if you want to sort the files" } | |
| file_contents = files.map { |f| CSV.read(f) } | |
| csv_string = CSV.generate do |csv| |
| require 'benchmark' | |
| REP = 100_000 | |
| dat = [1, 2, 3, 2, 4, 5, 4, 4] | |
| Benchmark.bmbm 25 do |x| | |
| x.report "Jan low level" do | |
| REP.times do | |
| dups = {} |