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 'github_api' | |
require 'git' | |
client = Github.new oauth_token: 'TOKEN', org: 'ORG_NAME' | |
BASE_DIR ||= '../repos' | |
i = 1 | |
while true | |
repos = client.repos.list(page: i) |
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
#lib/spree/api/responders_decorator.rb | |
Spree::Api::Responders::AppResponder.class_eval do | |
def template | |
options[:default_template] | |
end | |
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
config.action_controller.asset_host = proc do |source| | |
if source =~ /(ttf|ttc|otf|eot|woff|svg)$/ | |
"https://www.domain.com" | |
else | |
"https://cdn#{Digest::MD5.hexdigest(source).to_i(16) % 4 }.domain.com" | |
end | |
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
#!/bin/bash | |
MASTER_PID=`cat /home/deploy/app/shared/sockets/puma.state | grep pid | awk '{print $2}'` | |
PIDS=`ps auxwww | grep -v $MASTER_PID | grep [p]uma | awk '{print $2}'` | |
MAX_MEMORY=500000000 | |
for pid in $PIDS | |
do | |
MEM_USAGE=`ls -l /proc/$pid/as | awk '{print $5}'` | |
if [ $MEM_USAGE -gt $MAX_MEMORY ] | |
then | |
echo "Memory $MEM_USAGE exceeded $MAX_MEMORY killing $pid" |
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
#it retries only if Timeout is present | |
module HookTimeoutRetry | |
def on_failure_retry(e, *args) | |
key = "AutoRetry:#{self.name}:#{Digest::MD5.hexdigest(Resque.encode(args))}" | |
counter = Resque.redis.incr(key) | |
Resque.redis.expire(key, 180) | |
if [Timeout::Error, Redis::TimeoutError].include?(e.class) && counter <= 3 | |
Rails.logger.info "Performing #{self} caused an exception (#{e}). Retrying..." | |
Resque.enqueue self, *args |
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
if ENV['DEBUG_GEMLOADING'] | |
Bundler::Runtime.class_eval do | |
def Kernel.require file | |
puts Benchmark.measure("#{file}") { | |
super | |
}.format("%t - %n: %r") | |
end | |
end | |
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
def faster_paginate collection | |
output = '' | |
if collection.num_pages > 1 | |
output << "<nav class='pagination'>" | |
page_base = collection.current_page | |
if page_base > 4 | |
output << content_tag(:span, class: 'first') do | |
link_to raw(t 'views.pagination.first'), url_for(params.merge(page: 1)) | |
end | |
output << content_tag(:span, class: 'page gap') { '... '} |
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 Hash | |
def method_missing( symbol, *args ) | |
a, method = symbol.to_s.split('_') | |
if method | |
if self.has_key?(method.to_sym) || self.has_key?(method) | |
self[method.to_sym] || self[method] | |
else | |
if method.include?('=') | |
key = method.split('=').first.strip | |
if has_key?(key) |
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 pascalsTriangle(n) | |
(1..n).inject([]) do |final, level| | |
final << (1..level).inject([]) do |horizontal, index| | |
if index == 1 || index == level | |
horizontal << 1 | |
else | |
horizontal << (final[level - 2][index - 2]) + (final[level - 2][index - 1]) | |
end | |
end | |
final |
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 solution(roman) | |
roman.scan(/IV|IX|CM|XC|I|V|L|X|C|M|D/).inject(0) do |final, current| | |
final += case current | |
when 'IV' then 4 | |
when 'IX' then 9 | |
when 'XC' then 90 | |
when 'CM' then 900 | |
when 'I' then 1 | |
when 'V' then 5 | |
when 'X' then 10 |
NewerOlder