Skip to content

Instantly share code, notes, and snippets.

View 42thcoder's full-sized avatar
🎯
Focusing

Yunzheng 42thcoder

🎯
Focusing
View GitHub Profile
@johnbintz
johnbintz / simple-capistrano-docker-deploy.rb
Last active April 3, 2023 08:23
Simple Capistrano deploy for a Docker-managed app
# be sure to comment out the require 'capistrano/deploy' line in your Capfile!
# config valid only for Capistrano 3.1
lock '3.2.1'
set :application, 'my-cool-application'
# the base docker repo reference
set :name, "johns-stuff/#{fetch(:application)}"
@jandudulski
jandudulski / auth.rb
Last active September 14, 2022 12:09
CSRF on Grape
# based on http://api.rubyonrails.org/classes/ActionController/RequestForgeryProtection.html
module Auth
extend ActiveSupport::Concern
included do
helpers do
def session
env['rack.session']
end
@raecoo
raecoo / awk-example.sh
Last active September 21, 2023 07:12
awk/grep commands for Rails log analysis
# Access number
cat production.log | grep "^Processing" | wc | awk '{print $1}'
# Each IP access number
cat production.log | grep “^Processing” | awk ‘{print $4}’ | uniq -c
# Independent IP number
cat production.log | grep "^Processing" | awk '{print $4}' | uniq | wc | awk '{print $1}'
cat production.log | grep “^Processing” | awk ‘{print $4}’ | uniq | wc -l
ENV['RACK_ENV'] = 'test'
require 'bundler/setup'
require 'test/unit'
gem 'minitest'
require 'timecop'
require 'grape'
require 'logger'
Grape::API.logger = Logger.new('/dev/null')
@hectorperez
hectorperez / filter Rails logs which duration is greather than 500 ms.sh
Created September 4, 2014 17:18
filter Rails logs which duration > 500 ms
cat production.log | grep duration | awk 'a=$7,gsub(/[a-z=]/,"",a) {print a, $1, $2}' | awk '{if ($1 > 500) print $1, $2, $3}'
@hayeah
hayeah / gist:8e98cb08d1a12e87159d
Last active July 13, 2021 06:57
NodeJS Express 训练营课程安排

暖身周 (可选)

  • 写一个简单的 NPM package
  • 用 mocha 写测试
  • 用 CoffeeScript 写 NPM package
  • 实现 JS 类 (练习原型链)

第一周 - Connect Middleware

@lyoshenka
lyoshenka / ngrok-selfhosting-setup.md
Last active February 1, 2024 20:14
How to setup Ngrok with a self-signed SSL cert

Intro

The plan is to create a pair of executables (ngrok and ngrokd) that are connected with a self-signed SSL cert. Since the client and server executables are paired, you won't be able to use any other ngrok to connect to this ngrokd, and vice versa.

DNS

Add two DNS records: one for the base domain and one for the wildcard domain. For example, if your base domain is domain.com, you'll need a record for that and for *.domain.com.

Different Operating Systems

<?xml version="1.0" encoding="UTF-8" ?>
<opml version="1.0">
<head>
<title>寸志 subscriptions in Digg Reader</title>
</head>
<body>
<outline text="Framer Blog" title="Framer Blog" type="rss" xmlUrl="http://framerjs.tumblr.com/rss" htmlUrl="http://framerjs.tumblr.com/" />
<outline text="粉丝日志" title="粉丝日志" type="rss" xmlUrl="http://blog.fens.me/feed/" htmlUrl="http://blog.fens.me" />
<outline text="AngularJS" title="AngularJS" type="rss" xmlUrl="http://blog.angularjs.org/feeds/posts/default" htmlUrl="http://blog.angularjs.org/" />
<outline text="blog.izs.me" title="blog.izs.me" type="rss" xmlUrl="http://blog.izs.me/rss" htmlUrl="http://blog.izs.me/" />
@thebucknerlife
thebucknerlife / authentication_with_bcrypt_in_rails_4.md
Last active January 17, 2024 23:54
Simple Authentication in Rail 4 Using Bcrypt

#Simple Authentication with Bcrypt

This tutorial is for adding authentication to a vanilla Ruby on Rails app using Bcrypt and has_secure_password.

The steps below are based on Ryan Bates's approach from Railscast #250 Authentication from Scratch (revised).

You can see the final source code here: repo. I began with a stock rails app using rails new gif_vault

##Steps

# MODEL
class Case < ActiveRecord::Base
include Eventable
has_many :tasks
concerning :Assignment do
def assign_to(new_owner:, details:)
transaction do