Skip to content

Instantly share code, notes, and snippets.

View 3014zhangshuo's full-sized avatar
🎯
Coding

张硕 3014zhangshuo

🎯
Coding
View GitHub Profile
@subfuzion
subfuzion / curl.md
Last active April 24, 2025 13:48
curl POST examples

Common Options

-#, --progress-bar Make curl display a simple progress bar instead of the more informational standard meter.

-b, --cookie <name=data> Supply cookie with request. If no =, then specifies the cookie file to use (see -c).

-c, --cookie-jar <file name> File to save response cookies to.

@psobocinski
psobocinski / dummy_controller.rb
Created January 23, 2016 20:04
Asserting on a JSON response in a Rails controller test with MiniTest
class DummyController < ApplicationController
def do
render json: { balance: 50 }
end
end
@hateradio
hateradio / html64.rb
Last active April 29, 2024 05:58
ruby image to base64 string
require 'base64'
# converts attached PNGs into base64 strings
# Eg
# <img src="my.png" /> to <img src="data:image/png;base64,..." />
class To64Html
def initialize(path)
@jrumbut
jrumbut / 500-404-apache-error-report.sh
Last active February 14, 2021 21:55
Get 404 and 500 errors from apache error log
cat access.log.1 | grep " 500 " | awk -F'"' '{print $2,",",$4,",",$6}' > /home/ubuntu/500.log
cat access.log.1 | grep " 404 " | awk -F'"' '{print $2,",",$4,",",$6}' > /home/ubuntu/404.log
@equivalent
equivalent / big_array_duplicates_bench.rb
Last active June 21, 2021 10:16
fetch elements that occurred multiple times in Ruby Array
require 'benchmark'
require 'faker'
ary = []
100.times do
ary << Faker::Name.name
end
n = 100_000
@joseluisq
joseluisq / terminal-git-branch-name.md
Last active February 9, 2025 02:05
Add Git Branch Name to Terminal Prompt (Linux/Mac)

Add Git Branch Name to Terminal Prompt (Linux/Mac)

image

Open ~/.bash_profile in your favorite editor and add the following content to the bottom.

# Git branch in prompt.

parse_git_branch() {
@iangreenleaf
iangreenleaf / gist:b206d09c587e8fc6399e
Last active April 24, 2025 04:34
Rails naming conventions

Rails naming conventions

General Ruby conventions

Class names are CamelCase.

Methods and variables are snake_case.

Methods with a ? suffix will return a boolean.

@FUT
FUT / header_checks
Created November 14, 2014 10:22
Postfix email to Rails
# File: /etc/postfix/header_checks
# Add to the bottom of the file
/To:.*[email protected].*/ FILTER send_to_my_app:
@praseodym
praseodym / AESGCMUpdateAAD2.java
Last active May 13, 2024 10:20
JDK8 AES-GCM code example
import javax.crypto.*;
import javax.crypto.spec.GCMParameterSpec;
import java.nio.ByteBuffer;
import java.security.SecureRandom;
import java.util.Arrays;
public class AESGCMUpdateAAD2 {
// AES-GCM parameters
public static final int AES_KEY_SIZE = 128; // in bits
@itskingori
itskingori / application_controller.rb
Last active March 4, 2024 09:07 — forked from speed-of-light/application_controller.rb
How to handle exceptions like 401, 501, 404 in Rails
# As used with CanCan and Devise
class ApplicationController < ActionController::Base
protect_from_forgery
include ErrorResponseActions
rescue_from CanCan::AccessDenied, :with => :authorization_error
rescue_from ActiveRecord::RecordNotFound, :with => :resource_not_found
before_filter :authenticate!