Skip to content

Instantly share code, notes, and snippets.

@cfc1020
cfc1020 / nginx.conf
Last active August 29, 2015 14:01
/etc/nginx/nginx.conf
user nginx;
worker_processes 1;
error_log /var/log/nginx/error.log warn;
pid /var/run/nginx.pid;
events {
worker_connections 1024;
}
@cfc1020
cfc1020 / nginx.conf
Created May 17, 2014 12:36
My configure file is server-site nginx for unicorn
server {
listen 80;
server_name www.example.com;
root /home/user_name/web_app/public;
location / {
try_files $uri @unicorn;
}
@cfc1020
cfc1020 / look_and_say.rb
Last active March 22, 2021 12:24
ruby look and say sequence 1 11 21 1211
class String
def look_and_say_regexp
self.gsub(/(.)\1*/) { |match| "#{match.size}#{match[0]}" }
end
def look_and_say_chunk
self.chars.chunk { |c| c }.map { |c, arr| [arr.size, c] }.join
end
def look_and_say_manual
@cfc1020
cfc1020 / gist:ab77915cc3faca03597b
Last active May 13, 2020 09:34
_gallery.html.haml
#galleryModal.modal.fade{"aria-hidden" => "true", "aria-labelledby" => "myModalLabel", role: "dialog", tabindex: "-1"}
.modal-dialog
.modal-content
.modal-header
%button.close{"aria-label" => "Close", "data-dismiss" => "modal", type: "button"}
%span{"aria-hidden" => "true"} ×
%h4#galleryModalLabel.modal-title Modal title
.modal-body
#galleries.carousel.slide{"data-ride" => "carousel"}
.carousel-inner{role: "listbox"}
# Place all the behaviors and hooks related to the matching controller here.
# All this logic will automatically be available in application.js.
# You can use CoffeeScript in this file: http://coffeescript.org/
$ ->
$("input.numeric").numeric()
$('.advert-body-footer, #description').on 'click', =>
$('#description').toggleClass('text-overflow-on')
$(".advert-photos #galleries").on "slid.bs.carousel", =>
.advert-photos {
.carousel-inner {
margin-left: 65px;
width: 504px;
}
.carousel-control {
height: 300px;
}
.carousel-indicators::-webkit-scrollbar { width: 0 !important }
@cfc1020
cfc1020 / apache2-unicorn-conf
Created February 22, 2016 11:46 — forked from yonggu/apache2-unicorn-conf
Apache 2 configuration file with unicorn in Rails 4
<VirtualHost *:80>
ServerName example.com
ServerAlias *.example.com
DocumentRoot /rails_app_directory/public
# Redirect all requests that don't match a file on disk under DocumentRoot get proxied to Puma
RewriteEngine On
<Proxy balancer://unicornservers>
BalancerMember http://127.0.0.1:5100
@cfc1020
cfc1020 / secret_key_base
Created February 22, 2016 11:46 — forked from pablosalgadom/secret_key_base
app error: Missing `secret_key_base` for 'production' environment, set this value in `config/secrets.yml` (RuntimeError)
So i was using Rails 4.1 with Unicorn v4.8.2 and when i tried to deploy my app it doesn't start properly and into the unicorn.log file i found this error message:
"app error: Missing `secret_key_base` for 'production' environment, set this value in `config/secrets.yml` (RuntimeError)"
After a little research i found that Rails 4.1 change the way to manage the secret_key, so if we read the secrets.yml file located at exampleRailsProject/config/secrets.yml (you need to replace "exampleRailsProject" for your project name) you will find something like this:
# Do not keep production secrets in the repository,
# instead read values from the environment.
production:
secret_key_base: <%= ENV["SECRET_KEY_BASE"] %>
@cfc1020
cfc1020 / order_reporter.rb
Last active December 11, 2016 13:07
Need to write a good RSpec unit test for this small class(probably thinking about TDD&BDD first). And how could you improve this report class? Let's go :)
class OrderReporter
attr_reader :order
attr_reader :report
def initialize(order)
@order = order
end
def call
return generate_empty_report if order_items_blank?
@cfc1020
cfc1020 / sessions_and_conversations.markdown
Created September 30, 2018 15:25 — forked from jcasimir/sessions_and_conversations.markdown
Sessions and Conversations in Rails 3

Sessions and Conversations

HTTP is a stateless protocol. Sessions allow us to chain multiple requests together into a conversation between client and server.

Sessions should be an option of last resort. If there's no where else that the data can possibly go to achieve the desired functionality, only then should it be stored in the session. Sessions can be vulnerable to security threats from third parties, malicious users, and can cause scaling problems.

That doesn't mean we can't use sessions, but we should only use them where necessary.

Adding, Accessing, and Removing Data