This file contains hidden or 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
| #!/bin/bash | |
| usage() | |
| { | |
| cat << EOF | |
| usage: $0 options | |
| This script set ownership for all table, sequence and views for a given database | |
| Credit: Based on http://stackoverflow.com/a/2686185/305019 by Alex Soto |
This file contains hidden or 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 'rubygems' | |
| require 'dm-core' | |
| require 'dm-migrations' | |
| require 'dm-timestamps' | |
| DataMapper::Logger.new($stdout, :debug) | |
| DataMapper.setup(:default, "mysql://root@localhost/db_development") | |
| class Tester | |
| include DataMapper::Resource |
This file contains hidden or 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 'rubygems' | |
| require 'bundler' | |
| require 'fileutils' | |
| TMP_DIR = "/tmp/gems" | |
| #If directory exists, delete it and recreates. | |
| FileUtils.rm_rf(TMP_DIR) if File.exists?(TMP_DIR) | |
| FileUtils.mkdir TMP_DIR |
This file contains hidden or 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 'open-uri' | |
| require 'nokogiri' | |
| require 'yaml' | |
| start = 1 | |
| INCREMENT = 50 | |
| has_more = true | |
| File.open('universities.yml', 'w') do |file| | |
| while has_more do |
This file contains hidden or 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
| # spec/support/pundit.rb | |
| # Creates a 'grant_permission_to' matcher to better test Pundit policies | |
| # See: http://thunderboltlabs.com/blog/2013/03/27/testing-pundit-policies-with-rspec/ | |
| RSpec::Matchers.define :grant_permission_to do |action| | |
| match do |policy| | |
| policy.public_send("#{action}?") | |
| end |
This file contains hidden or 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
| RSpec::Matchers.define :have_content_type do |content_type| | |
| MIME_TYPES = { json: 'application/json' } | |
| match do |response| | |
| response_content_type = response.header['Content-Type'] | |
| response_content_type.split(";").include?(MIME_TYPES[content_type]) | |
| end | |
| description do |
This file contains hidden or 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 dl_for(instance, attribute) | |
| content = content_tag(:dt, class: "input-lg") do | |
| instance.class.human_attribute_name(attribute) | |
| end | |
| content << content_tag(:dd, class: "input-lg") do | |
| if block_given? | |
| yield | |
| else |
This file contains hidden or 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 AppConfig < ActiveRecord::Base | |
| validates :parameter, uniqueness: true, presence: true | |
| def self.get(parameter) | |
| AppConfig.where(parameter: parameter).first.try(:value) | |
| end | |
| def self.set(parameter, value) | |
| param = AppConfig.find_or_initialize_by(parameter: parameter) |
This file contains hidden or 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 NetworkExplorerController < ApplicationController | |
| def index | |
| end | |
| def get_root_nodes | |
| roots = NetworkExplorerService.roots(current_user) | |
| respond_with(roots) | |
| end |
This file contains hidden or 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
| module CollectionMath | |
| class << self | |
| # Returns nil instead of 0 for an empty array | |
| def sum_values(collection) | |
| values = if block_given? | |
| collection.map{ |item| yield item }.compact | |
| else |
OlderNewer