Usage:
#fill_watermark_text(img, width, height, text, gravity = "Center")
attachment_url(object, :attachment, :fill_watermark_text, 800, 600, "My Watermark")
$(document).ready -> | |
Dropzone.autoDiscover = false | |
$(document).on 'shown.bs.modal', '.upload-modal', -> | |
modal = this | |
previewTemplate = $('#' + modal.id + ' .dz-file-preview')[0].innerHTML | |
# Make sure to only initialize the dropzone once. | |
if ( $('#' + modal.id + ' .dropzone:not(.dz-attached)').length ) | |
dropzone = new Dropzone('#' + modal.id + ' .dropzone', { |
class SimpleTime | |
# attr_accessor :time | |
def self.parse(time) | |
return time if time.is_a?(SimpleTime) | |
return nil if time.nil? || (time.is_a?(String) && time.empty?) | |
return nil unless (time.is_a?(String) && time.upcase.match(/\d{1,2}:\d{2} [AP]M/)) || (time.is_a?(Hash) && time[:hour].present? && time[:minute].present? && time[:meridiem].present?) | |
self.new(time) | |
end |
# Redis Cheatsheet | |
# All the commands you need to know | |
redis-server /path/redis.conf # start redis with the related configuration file | |
redis-cli # opens a redis prompt | |
# Strings. |
Usage:
#fill_watermark_text(img, width, height, text, gravity = "Center")
attachment_url(object, :attachment, :fill_watermark_text, 800, 600, "My Watermark")
# lib/omniauth/facebook.rb | |
require 'httparty' | |
module Omniauth | |
class Facebook | |
include HTTParty | |
# The base uri for facebook graph API | |
base_uri 'https://graph.facebook.com/v2.3' |
My largest Sidekiq application had a memory leak and I was able to find and fix it in just few hours spent on analyzing Ruby's heap. In this post I'll show my profiling setup.
As you might know Ruby 2.1 introduced a few great changes to ObjectSpace, so now it's much easier to find a line of code that is allocating too many objects. Here is great post explaining how it's working.
I was too lazy to set up some seeding and run it locally, so I checked that test suite passes when profiling is enabled and pushed debugging to production. Production environment also suited me better since my jobs data can't be fully random generated.
So, in order to profile your worker, add this to your Sidekiq configuration:
if ENV["PROFILE"]
SSH into Root
$ ssh root@123.123.123.123
Change Root Password
# This library fixes common problems with turbolinks | |
# - Overwrite setTimeout and setInterval to intercept generated ID's | |
# - Keep track of Ajax requests | |
# | |
# When turbolinks' unload event is called, we: | |
# - Cancel all setTimeouts and setIntervals | |
# - Abort all still running Ajax requests | |
$.turboTurbo = |
echo "* Updating system" | |
apt-get update | |
apt-get -y upgrade | |
echo "* Installing packages" | |
apt-get -y install build-essential libmagickcore-dev imagemagick libmagickwand-dev libxml2-dev libxslt1-dev git-core nginx redis-server curl nodejs htop | |
id -u deploy &> /dev/null | |
if [ $? -ne 0 ] | |
then |
require 'oauth' | |
require 'httpclient' | |
require 'json' | |
class SimpleTwitter | |
def initialize(config) | |
@config = config | |
@http_client = HTTPClient.new | |
end |