⌘T | go to file |
⌘⌃P | go to project |
⌘R | go to methods |
⌃G | go to line |
⌘KB | toggle side bar |
⌘⇧P | command prompt |
(function ($) { | |
// Author: Mohamad El-Husseini, www.mohamad.im | |
// Light weight character counter for jQuery. | |
// Example: http://jsfiddle.net/yHPg7/6/ | |
"use strict"; | |
$.fn.counter = function (options) { | |
options = $.extend($.fn.counter.defaults, options); |
(($) -> | |
# Author: Mohamad El-Husseini, www.mohamad.im | |
# Light weight character counter for jQuery. | |
# Example: http://jsfiddle.net/yHPg7/6/ | |
"use strict" | |
$.fn.counter = (options) -> | |
defaultText = -> | |
options.defaultText.replace /minSize/g, options.minSize | |
count = (elem) -> |
This setup was used successfully on a DigitalOcean VPS. After much trial and error, and following a number of disparate guides and tutorials, I was able to distil the process to the information found in this gist.
Before getting started, you should create a new server droplet. Login to verify that everything is working correctly.
ssh [email protected]
A sorting algorithm for sorting by "hotness", roughly based on Reddit's algorithm with a few tweeks.
scope :order_by_hot, ->
{ order("round((votes_count - 1) / POW(DATE_PART('day', Now() - created_at) * 24 + DATE_PART('hour', Now() - created_at) + 2, 1.5)::numeric, 8) DESC, votes_count DESC") }
By default, Rails applications build URLs based on the primary key -- the id
column from the database. Imagine we have a Person
model and associated controller. We have a person record for Bob Martin
that has id
number 6
. The URL for his show page would be:
/people/6
But, for aesthetic or SEO purposes, we want Bob's name in the URL. The last segment, the 6
here, is called the "slug". Let's look at a few ways to implement better slugs.
class SignedUrlsController < ApplicationController | |
def s3 | |
# Create client and set bucket | |
client = AWS::S3.new | |
bucket = client.buckets[ENV['S3_BUCKET']] | |
# Extract file extension since we're renaming the file | |
extension = File.extname(params[:image_name]).downcase | |
# Get mime-type from extension |
require "i18n" | |
class EmailAddress | |
VALID_EMAIL_ADDRESS_REGEX = /\A[\w+\-.]+@[a-z\d\-.]+\.[a-z]+\z/i | |
def self.malformed?(email) | |
email !~ VALID_EMAIL_ADDRESS_REGEX | |
end | |
def self.valid?(email) |
<% flash.each do |key, message| %> | |
<%= content_tag :div, class: "alert alert-full-page alert-#{key} alert-dismissable", role: "alert" do %> | |
<button type="button" class="close" data-dismiss="alert" aria-label="Close"> | |
<span aria-hidden="true">×</span> | |
</button> | |
<%= message %> | |
<% end %> | |
<% end %> |