Skip to content

Instantly share code, notes, and snippets.

@zealinux
zealinux / README.md
Created May 11, 2018 07:42 — forked from magnetikonline/README.md
Bash getopts usage template.

Bash getopts usage template

#!/bin/bash -e

function usage {

	cat <<EOM
Usage: $(basename "$0") [OPTION]...
@zealinux
zealinux / db.rake
Created April 21, 2018 03:57 — forked from hopsoft/db.rake
Rails rake tasks for dump & restore of PostgreSQL databases
# lib/tasks/db.rake
namespace :db do
desc "Dumps the database to db/APP_NAME.dump"
task :dump => :environment do
cmd = nil
with_config do |app, host, db, user|
cmd = "pg_dump --host #{host} --username #{user} --verbose --clean --no-owner --no-acl --format=c #{db} > #{Rails.root}/db/#{app}.dump"
end
puts cmd
@zealinux
zealinux / linux-http-tcp.md
Created March 2, 2018 02:43 — forked from v5tech/linux-http-tcp.md
linux下查看http 并发和 tcp连接数

linux查看httpd进程数

ps -ef | grep httpd | wc -l

查看Apache的并发请求数及其TCP连接状态

netstat -n | awk '/^tcp/ {++S[$NF]} END {for(a in S) print a, S[a]}'
#!/bin/bash
bundle check || bundle install --jobs 4 --retry 5
pids=( server.pid realtime_updater.pid )
for file in "${pids[@]}"
do
path="tmp/pids/$file"
if [ -f $path ]; then
rm $path
fi
@zealinux
zealinux / gist:c54d79740fd5e1194596583f105efb4b
Created January 9, 2018 05:38 — forked from mtigas/gist:952344
Mini tutorial for configuring client-side SSL certificates.

Client-side SSL

For excessively paranoid client authentication.

Using self-signed certificate.

Create a Certificate Authority root (which represents this server)

Organization & Common Name: Some human identifier for this server CA.

openssl genrsa -des3 -out ca.key 4096
openssl req -new -x509 -days 365 -key ca.key -out ca.crt
@zealinux
zealinux / send_data-send_file-remote-images-download
Created November 22, 2017 05:55 — forked from maxivak/send_data-send_file-remote-images-download
Rails. Download remote image as attachment in browser
# in controller
# for local files
send_file '/path/to/file', :type => 'image/jpeg', :disposition => 'attachment'
# for remote files
require 'open-uri'
url = 'http://someserver.com/path/../filename.jpg'
data = open(url).read
send_data data, :disposition => 'attachment', :filename=>"photo.jpg"
@zealinux
zealinux / 01-safe-download.rb
Created November 22, 2017 05:52 — forked from janko/01-safe-download.rb
A safe way in Ruby to download a file to disk using open-uri (with/without comments)
require "open-uri"
require "net/http"
Error = Class.new(StandardError)
DOWNLOAD_ERRORS = [
SocketError,
OpenURI::HTTPError,
RuntimeError,
URI::InvalidURIError,
@zealinux
zealinux / java_for_rubyists.md
Created October 16, 2017 06:11 — forked from nilbus/java_for_rubyists.md
Some Java basics for Rubyists
  1. Java uses static, declared typing:

    String hello = "Hello, World!";
    List<String> phrases = new ArrayList<String>;
    phrases.add(hello);
    phrases.add(null);
    phrases.add(123); // Compile error! Not a string.
@zealinux
zealinux / .dockerignore
Created September 16, 2017 08:12 — forked from davidderus/.dockerignore
Docker + Rails + Puma + Postgres + Nginx
.git
.gitignore
doc
.yardoc
coverage
jsdoc
tmp
log
README.md
public/uploads/
require 'faraday'
field_file_url = 'http://localhost/blah'
file_to_upload = 'test.txt'
connection = Faraday.new(field_file_url) do |builder|
builder.request :multipart
builder.request :url_encoded
builder.adapter :net_http
end