Skip to content

Instantly share code, notes, and snippets.

@patsanch
patsanch / imagemagick-ubuntu.txt
Created December 16, 2022 04:00 — forked from nickferrando/imagemagick-ubuntu.txt
Install ImageMagick with JPG, PNG and TIFF Delegates - Ubuntu (20.04)
#These are the steps required in order to Install ImageMagick with JPG, PNG and TIFF delegates.
sudo apt-get update
#Install Build-Essential in order to configure and make the final Install
sudo apt-get install build-essential
#libjpg62-dev required in order to work with basic JPG files
/// Use SharedPreferences in Flutter effortlessly
/// https://medium.com/@simonpham/use-sharedpreferences-in-flutter-effortlessly-835bba8f7418
// utils/shared_prefs.dart
class SharedPrefs {
static SharedPreferences _sharedPrefs;
factory SharedPrefs() => SharedPrefs._internal();
SharedPrefs._internal();
@patsanch
patsanch / Gemfile
Created June 25, 2020 00:09 — forked from dhh/Gemfile
HEY's Gemfile
ruby '2.7.1'
gem 'rails', github: 'rails/rails'
gem 'tzinfo-data', '>= 1.2016.7' # Don't rely on OSX/Linux timezone data
# Action Text
gem 'actiontext', github: 'basecamp/actiontext', ref: 'okra'
gem 'okra', github: 'basecamp/okra'
# Drivers
@patsanch
patsanch / nginx-tuning.md
Created May 1, 2020 01:49 — forked from denji/nginx-tuning.md
NGINX tuning for best performance

Moved to git repository: https://github.com/denji/nginx-tuning

NGINX Tuning For Best Performance

For this configuration you can use web server you like, i decided, because i work mostly with it to use nginx.

Generally, properly configured nginx can handle up to 400K to 500K requests per second (clustered), most what i saw is 50K to 80K (non-clustered) requests per second and 30% CPU load, course, this was 2 x Intel Xeon with HyperThreading enabled, but it can work without problem on slower machines.

You must understand that this config is used in testing environment and not in production so you will need to find a way to implement most of those features best possible for your servers.

Multiple MySQL Versions for Development

Options included below:

  • Using Docker docker-compose
  • Using Homebrew brew

Using Docker (recommended)

This gist was originally created for Homebrew before the rise of Docker, yet it may be best to avoid installing mysql via brew any longer. Instead consider adding a barebones docker-compose.yml for each project and run docker-compose up to start each project's mysql service.

@patsanch
patsanch / states.rb
Created July 11, 2019 20:47 — forked from dblandin/states.rb
Ruby array of US state name and abbreviations
states = Array[ ["AK", "Alaska"],
["AL", "Alabama"],
["AR", "Arkansas"],
["AS", "American Samoa"],
["AZ", "Arizona"],
["CA", "California"],
["CO", "Colorado"],
["CT", "Connecticut"],
["DC", "District of Columbia"],
["DE", "Delaware"],
@patsanch
patsanch / encryptor.rb
Created August 31, 2018 21:42 — forked from aloucas/encryptor.rb
How to create dynamic attr_accessors (getters/setters) for encrypted attributes in a Ruby on Rails 5 Model.
# lib/encryptor.rb
# Module to dynamic encrypt attributes per model
module Encryptor
def has_encrypted_attributes(*attrs)
attrs.each do |attr|
# Define the dynamic getter
define_method(attr) do
self[attr].present? ? Encryptor.crypt.decrypt_and_verify(self[attr]) : self[attr]
end
# Define the dynamic setter
@patsanch
patsanch / stress-test.sh
Created March 31, 2018 01:08 — forked from jddonovan/stress-test.sh
naive http server stress tester using cURL
#!/bin/bash
#### Default Configuration
CONCURRENCY=4
REQUESTS=100
ADDRESS="http://localhost:8080/"
show_help() {
cat << EOF
# This patch is required:
# For: google authentication.
# When: Running rails on a port other than 80 where a proxy server proxies to rails.
# Cause: 1. Rack is not able to figure out that it should not set the realm url port to the rails custom port in case the full_host is mentioned using
# OmniAuth.config.full_host
# 2. OpenID tries to validate the incoming callback url with the custom port that rails is running on and throws the error "return_to #{meth.to_s} does not match".
env = Rails.env
if env != "development"
@patsanch
patsanch / passenger-management.rb
Created April 6, 2016 17:49 — forked from loopj/passenger-management.rb
Checks memory usage of all paseenger child process and kill if grows too large. Additionally kill off long running passengers to prevent memory leak issues (similar to the PassengerMaxRequests config variable in apache's passenger version, but works on bo
#!/usr/bin/env ruby
#
# Passenger management script
# By James Smith http://loopj.com
# Based heavily on a similar script by Jon Bettcher
#
# Check memory usage of all paseenger child process and kill if grows
# too large.
#