Skip to content

Instantly share code, notes, and snippets.

@endolith
endolith / Has weird right-to-left characters.txt
Last active July 17, 2024 12:41
Unicode kaomoji smileys emoticons emoji
ּ_בּ
בּ_בּ
טּ_טּ
כּ‗כּ
לּ_לּ
מּ_מּ
סּ_סּ
תּ_תּ
٩(×̯×)۶
٩(̾●̮̮̃̾•̃̾)۶
# unicorn_rails -c /data/github/current/config/unicorn.rb -E production -D
rails_env = ENV['RAILS_ENV'] || 'production'
# 16 workers and 1 master
worker_processes (rails_env == 'production' ? 16 : 4)
# Load rails+github.git into the master before forking workers
# for super-fast worker spawn times
preload_app true
@czottmann
czottmann / Procfile
Created June 15, 2011 13:43
Example of a Foreman/Capistrano/upstart setup
worker: QUEUE=* bundle exec rake environment resque:work
scheduler: bundle exec rake environment resque:scheduler
@rgreenjr
rgreenjr / postgres_queries_and_commands.sql
Last active July 27, 2024 16:50
Useful PostgreSQL Queries and Commands
-- show running queries (pre 9.2)
SELECT procpid, age(clock_timestamp(), query_start), usename, current_query
FROM pg_stat_activity
WHERE current_query != '<IDLE>' AND current_query NOT ILIKE '%pg_stat_activity%'
ORDER BY query_start desc;
-- show running queries (9.2)
SELECT pid, age(clock_timestamp(), query_start), usename, query
FROM pg_stat_activity
WHERE query != '<IDLE>' AND query NOT ILIKE '%pg_stat_activity%'
@tkrotoff
tkrotoff / event.rb
Created October 9, 2012 13:45
Rails JSON serialization and deserialization
class Event < ActiveRecord::Base
include EventJSON
attr_accessible *EventJSON.attributes
validates :starts_at, presence: true
validates :ends_at, presence: true
validates :all_day, inclusion: { in: [true, false] }
end
@inkel
inkel / ruby-no-cflags.txt
Created December 1, 2012 12:08
Benchmark for comparison of homebrew's ruby with and without CFLAGS="-march=native -O3"
>> /usr/bin/time -l ruby thebench.rb 30 1000
Rehearsal --------------------------------------------------------
fib(30) 0.260000 0.000000 0.260000 ( 0.255475)
1000 tempfiles 0.120000 0.250000 0.370000 ( 0.429621)
----------------------------------------------- total: 0.630000sec
user system total real
fib(30) 0.260000 0.000000 0.260000 ( 0.259108)
1000 tempfiles 0.130000 0.270000 0.400000 ( 0.848950)
@techniq
techniq / audit_mixin.py
Created March 16, 2013 01:05
Useful SQLAlchemy Mixins
from datetime import datetime
from sqlalchemy import Column, Integer, DateTime, ForeignKey
from sqlalchemy.orm import relationship
from sqlalchemy.ext.declarative import declared_attr
from flask_security import current_user
class AuditMixin(object):
created_at = Column(DateTime, default=datetime.now)
updated_at = Column(DateTime, default=datetime.now, onupdate=datetime.now)
@jwilkins
jwilkins / httparallel.rb
Last active March 25, 2020 13:15
parallel http/https download with typhoeus
#!/usr/bin/env ruby
# 25s curl -o all.gz.curl http://download.openwall.net/pub/passwords/wordlists/all.gz
# 11s for this script with 4 parallel requests
require 'typhoeus'
def pfetch(url, splits=4)
response = Typhoeus.head(url)
parallelize = false
basename = File.basename(url)
size = nil
module Foo
class Error < StandardError; end
end
module Foo
class Baz
def initialize
puts Error
end
end
@demisx
demisx / active_record_objects_autosave.md
Last active July 4, 2024 14:20
When Active Record Child Objects are Autosaved in Rails

belongs_to:

  1. Assigning an object to a belongs_to association does not automatically save the object. It does not save the associated object either.

has_one:

  1. When you assign an object to a has_one association, that object is automatically saved (in order to update its foreign key).
  2. In addition, any object being replaced is also automatically saved, because its foreign key will change too
  3. If either of these saves fails due to validation errors, then the assignment statement returns false and the assignment itself is cancelled.
  4. If the parent object (the one declaring the has_one association) is unsaved (that is, new_record? returns true) then the child objects are not saved. They will automatically when the parent object is saved.