This file contains 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 CachedMethod | |
def self.included(base) | |
base.class_eval do | |
@method_cache_validators = Hash.new(0) | |
extend ClassMethods | |
end | |
end | |
module ClassMethods |
This file contains 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
# Usage: ruby fetch_logos.rb <FULL_DOMAIN> | |
require 'httparty' | |
require 'nokogiri' | |
require 'css_parser' | |
require 'byebug' | |
class Array | |
def self.wrap(object) | |
if !object.is_a?(Array) |
This file contains 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
let isRunning = false | |
const foo = function() { | |
isRunning = true | |
console.log('called') | |
isRunning = false | |
} | |
const events = ['click', 'mousedown'] | |
let func = function(eventsArr, cb) { |
This file contains 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 String | |
module WidgetExceptions | |
class InvalidWidget < ArgumentError; end | |
end | |
def widget_inject(widgets = []) | |
self_with_widgets = self.clone | |
widgets.sort_by {|w| w[:position] }.reverse.each do |widget| | |
raise WidgetExceptions::InvalidWidget, "widget must be a hash, was #{widget.class.name}" unless widget.is_a?(Hash) |
This file contains 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
check process thin-3000 with pidfile /var/www/html/redmine2/current/tmp/pids/thin.3000.pid | |
start program = "cd /var/www/html/redmine2/current && /usr/local/rvm/bin/rvm default do bundle exec thin start -C /var/www/html/redmine2/current/config/thin/performance.yml" | |
stop program = "cd /var/www/html/redmine2/current && /usr/local/rvm/bin/rvm default do bundle exec thin stop -C /var/www/html/redmine2/current/config/thin/performance.yml" | |
if 3 restarts within 5 cycles then timeout | |
if totalmem is greater than 400.0 MB for 2 cycles then restart | |
group thin |
This file contains 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
check process thin-3000 with pidfile /var/www/html/redmine2/current/tmp/pids/thin.3000.pid | |
start program = "cd /var/www/html/redmine2/current && /usr/local/rvm/bin/rvm default do bundle exec thin start -C /var/www/html/redmine2/current/config/thin/performance.yml" | |
stop program = "cd /var/www/html/redmine2/current && /usr/local/rvm/bin/rvm default do bundle exec thin stop -C /var/www/html/redmine2/current/config/thin/performance.yml" | |
if 3 restarts within 5 cycles then timeout | |
if totalmem is greater than 400.0 MB for 2 cycles then restart | |
group thin |
This file contains 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 FavoritesManager | |
attr_reader :user_id | |
def initialize(user_id) | |
@user_id = user_id | |
@client = REDIS | |
end | |
def favorite_post(post) |
This file contains 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 PostsController < ApplicationController | |
before_action :find_post, only: [:show, :edit, :destroy] | |
skip_before_action :verify_authenticity_token, only: [:create, :update, :destroy] | |
respond_to :html, :json, :xml | |
def index | |
@posts = Post.all | |
respond_with(@posts) |
This file contains 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 "socket" | |
class Client | |
def initialize(host, port) | |
@server = TCPSocket.open( host, port ) | |
@request = nil | |
@response = nil | |
listen | |
send | |
@request.join |
This file contains 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 do_we_have?(hash = {}, keys = []) | |
hash_keys = hash.keys.map {|key| key.to_s } | |
found_all = true | |
keys.each do |key| | |
unless hash_keys.include?(key) | |
found_all = false | |
end | |
end | |
return found_all | |
end |
NewerOlder