Skip to content

Instantly share code, notes, and snippets.

View freegenie's full-sized avatar

Fabrizio Regini freegenie

View GitHub Profile
@r00takaspin
r00takaspin / puma.service
Created May 11, 2018 15:29
Run puma web server with RVM from systemd
[Unit]
Description=Puma HTTP Server
After=network.target
# Uncomment for socket activation (see below)
# Requires=puma.socket
[Service]
# Foreground process (do not use --daemon in ExecStart or config.rb)
Type=simple
@iamdbc
iamdbc / logrotate-puma-rails
Last active September 20, 2023 14:57
logrotate for puma on rails
# file location: /etc/logrotate.d
/home/deploy/app/your-app/shared/log/*.log {
daily
missingok
rotate 14
compress
delaycompress
dateext
notifempty
@welshstew
welshstew / activemq-jmssender.groovy
Created September 12, 2014 04:09
send jms messages to activemq with a neat groovy script
@Grab(group='org.apache.activemq',module = 'activemq-all', version='5.8.0')
import org.apache.activemq.ActiveMQConnectionFactory
import javax.jms.*
def brokerUrl = 'tcp://localhost:61616'
def queue = 'the.soapoverjms.service'
def soapAction = 'urn:sixtree:soapoverjms:dosomething'
def reader = new BufferedReader(new InputStreamReader(System.in))
@mperham
mperham / gist:7d763bdc42465caf17c7
Last active August 29, 2015 14:02
Rule execution

I want to build a system which uses rules. These rules will change hourly (i.e. "this rule is effective from 2pm to 6pm"). The rules must support arbitrarily complex logic on just 2-3 pre-defined variables and result in a boolean:

item.a > 10 && item.b == 0 || item.category == FOOTWEAR

These rules will be executed hundreds of times per second so I can't afford the overhead of plain old eval. I want to reload the current effective ruleset from the database hourly, precompile each rule's logic string and execute it via the quickest method possible. It might look something like this:

class Rule
@parzonka
parzonka / install-gradle-centos.sh
Last active September 9, 2022 20:09
Install gradle on redhat/centos linux
# installs to /opt/gradle
# existing versions are not overwritten/deleted
# seamless upgrades/downgrades
# $GRADLE_HOME points to latest *installed* (not released)
gradle_version=2.9
wget -N https://services.gradle.org/distributions/gradle-${gradle_version}-all.zip
sudo unzip -foq gradle-${gradle_version}-all.zip -d /opt/gradle
sudo ln -sfn gradle-${gradle_version} /opt/gradle/latest
sudo printf "export GRADLE_HOME=/opt/gradle/latest\nexport PATH=\$PATH:\$GRADLE_HOME/bin" > /etc/profile.d/gradle.sh
. /etc/profile.d/gradle.sh
@eric1234
eric1234 / README.md
Last active April 9, 2021 02:09
Generate non-digest versions of asset files for Rails 4 (similar to the way Rails 3 worked)

Purpose

Restores the generation of non-digest assets from Rails 3. This is essential for when those assets must be referenced outside of Rails. Maybe some of your app in in another language, or maybe some of your JavaScript is dynamically and conditionally loaded.

Usage

Compile your assets with the regular task:

@rwdaigle
rwdaigle / bundle.pem
Created May 2, 2013 16:44
Comodo SSL certificate chain. Last updated May 2, 2013
-----BEGIN CERTIFICATE-----
MIIFAzCCA+ugAwIBAgIQGLLLuqME8aAPwfLzJkYqSjANBgkqhkiG9w0BAQUFADCB
gTELMAkGA1UEBhMCR0IxGzAZBgNVBAgTEkdyZWF0ZXIgTWFuY2hlc3RlcjEQMA4G
A1UEBxMHU2FsZm9yZDEaMBgGA1UEChMRQ09NT0RPIENBIExpbWl0ZWQxJzAlBgNV
BAMTHkNPTU9ETyBDZXJ0aWZpY2F0aW9uIEF1dGhvcml0eTAeFw0wNjEyMDEwMDAw
MDBaFw0xOTEyMzEyMzU5NTlaMHIxCzAJBgNVBAYTAkdCMRswGQYDVQQIExJHcmVh
dGVyIE1hbmNoZXN0ZXIxEDAOBgNVBAcTB1NhbGZvcmQxGjAYBgNVBAoTEUNPTU9E
TyBDQSBMaW1pdGVkMRgwFgYDVQQDEw9Fc3NlbnRpYWxTU0wgQ0EwggEiMA0GCSqG
SIb3DQEBAQUAA4IBDwAwggEKAoIBAQCt8AiwcsargxIxF3CJhakgEtSYau2A1NHf
5I5ZLdOWIY120j8YC0YZYwvHIPPlC92AGvFaoL0dds23Izp0XmEbdaqb1IX04XiR
if ! $(psql template1 -c 'SHOW SERVER_ENCODING' | grep -q UTF8); then
psql postgres -c "update pg_database set datallowconn = TRUE where datname = 'template0';"
psql template0 -c "update pg_database set datistemplate = FALSE where datname = 'template1';"
psql template0 -c "drop database template1;"
psql template0 -c "create database template1 with template = template0 encoding = 'UTF8';"
psql template0 -c "update pg_database set datistemplate = TRUE where datname = 'template1';"
psql template1 -c "update pg_database set datallowconn = FALSE where datname = 'template0';"
fi
@freegenie
freegenie / unicorn.conf.rb
Created December 13, 2012 00:14
Unicorn after_fork block to have Rails write logs to a separare file for each worker.
after_fork do |server, worker|
log_path = Rails.root.join('log',"#{Rails.env}.#{worker.nr}.log")
new_logger = Logger.new(log_path)
new_logger.level = Logger::INFO
Rails.logger.flush
Rails.logger.close
Rails.logger = Rails.application.config.logger = ActiveSupport::TaggedLogging.new(new_logger)
@ryanb
ryanb / abilities.rb
Created September 15, 2012 19:23
How you can break up large Ability class in CanCan
module Abilities
def self.ability_for(user)
if user.admin?
AdminAbility.new(user)
else user
MemberAbility.new(user)
else
GuestAbility.new
end
end