Skip to content

Instantly share code, notes, and snippets.

@ychaker
ychaker / upload_doc.coffee
Last active May 10, 2017 02:05
Rails + Refile + Dropzone (6)
$(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', {
@kevinvangelder
kevinvangelder / simple_time.rb
Created November 21, 2016 19:16
Simple Time class for string-only time in Ruby
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
@LeCoupa
LeCoupa / redis_cheatsheet.bash
Last active June 26, 2024 15:54
Redis Cheatsheet - Basic Commands You Must Know --> UPDATED VERSION --> https://github.com/LeCoupa/awesome-cheatsheets
# 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.
@zyphlar
zyphlar / REFILE-WATERMARK.md
Last active May 18, 2019 19:48
Adds Watermarking ability to Refile

Usage:

#fill_watermark_text(img, width, height, text, gravity = "Center")
attachment_url(object, :attachment, :fill_watermark_text, 800, 600, "My Watermark")
@a14m
a14m / facebook.rb
Last active February 24, 2022 18:08
Gist for manually OAuth2 facebook for Rails APIs
# 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'
@krasnoukhov
krasnoukhov / 2013-01-07-profiling-memory-leaky-sidekiq-applications-with-ruby-2.1.md
Last active October 4, 2023 21:53
Profiling memory leaky Sidekiq applications with Ruby 2.1

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"]
@ChuckJHardy
ChuckJHardy / digital_ocean_setup.md
Last active October 27, 2023 17:51
DigitalOcean Ubuntu 14.04 x64 + Rails 4 + Nginx + Unicorn + PostgreSQL + Capistrano 3 Setup Instructions

DigitalOcean Ubuntu 14.04 x64 + Rails 4 + Nginx + Unicorn + PostgreSQL + Capistrano 3

SSH into Root

$ ssh root@123.123.123.123

Change Root Password

@dv
dv / turbo_turbo.js.coffee
Last active March 2, 2021 04:05
Fix setTimout, setInterval, and global ajax requests when using Turbolinks
# 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 =
@jancuk
jancuk / bash-rails
Created October 29, 2014 02:32
bash-rails
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
@coderberry
coderberry / simple-twitter.rb
Created October 21, 2014 18:56
Application oauth2 for Twitter using Ruby
require 'oauth'
require 'httpclient'
require 'json'
class SimpleTwitter
def initialize(config)
@config = config
@http_client = HTTPClient.new
end