Skip to content

Instantly share code, notes, and snippets.

View equivalent's full-sized avatar
:octocat:
I'm IDDQD + IDKFA for Ruby on Rails

Tomas Valent equivalent

:octocat:
I'm IDDQD + IDKFA for Ruby on Rails
View GitHub Profile
@mrmartineau
mrmartineau / stimulus.md
Last active April 19, 2024 09:41
Stimulus cheatsheet
@fiftin
fiftin / Convert PostgreSQL to SQLite
Created October 5, 2015 07:04
Convert PostgreSQL to SQLite
1. Dump the data only sql to file
$ pg_dump --data-only --inserts YOUR_DB_NAME > dump.sql
2. scp to local
3. Remove the SET statements at the top
such as:
SET statement_timeout = 0;
SET client_encoding = 'SQL_ASCII';
4. Remove the setval sequence queries
@0x0dea
0x0dea / process_gsub.rb
Created April 26, 2015 23:08
Process.gsub lets you search and replace within your process's live memory!
def Process.gsub pat, sub
mem = File.open('/proc/self/mem', 'r+')
maps = File.open('/proc/self/maps')
maps.each do |map|
from, to, perms, offset = map.scan(/(\h+)-(\h+) (\S+) (\h+)/)[0]
if perms['rw']
from, to = [from, to].map { |addr| addr.hex + offset.hex }
data = mem.tap { |m| m.seek from }.read(to - from) rescue next
@cybersamx
cybersamx / capybara_cheat_sheet.rb
Last active June 26, 2022 08:32
Capybara (visit/page) cheat sheet
# Navigation
visit('/resources')
visit(resource_path(resource))
# Clicking buttons and hyperlinks
click_button('Submit Button')
click_link('Link Text')
click_link('Link id')
click('Link or button')
@rkjha
rkjha / nginx-config-rails4-with-puma-ssl-version.conf
Last active November 2, 2023 11:57
Nginx config for rails 4 application using puma [ssl and non-ssl version]
upstream myapp_puma {
server unix:/tmp/myapp_puma.sock fail_timeout=0;
}
# for redirecting to https version of the site
server {
listen 80;
rewrite ^(.*) https://$host$1 permanent;
}
@datenimperator
datenimperator / sqlite.rb
Created November 22, 2013 16:19
Speed up your Rails sqlite database for large dataset. This should be a Rails initializer, goes into config/initializers.
if ::ActiveRecord::Base.connection_config[:adapter] == 'sqlite3'
if c = ::ActiveRecord::Base.connection
# see http://www.sqlite.org/pragma.html for details
# Page size of the database. The page size must be a power of two between 512 and 65536 inclusive
c.execute 'PRAGMA main.page_size=4096;'
# Suggested maximum number of database disk pages that SQLite will hold in memory at once per open database file
c.execute 'PRAGMA main.cache_size=10000;'
@chanks
chanks / gist:7585810
Last active February 29, 2024 03:50
Turning PostgreSQL into a queue serving 10,000 jobs per second

Turning PostgreSQL into a queue serving 10,000 jobs per second

RDBMS-based job queues have been criticized recently for being unable to handle heavy loads. And they deserve it, to some extent, because the queries used to safely lock a job have been pretty hairy. SELECT FOR UPDATE followed by an UPDATE works fine at first, but then you add more workers, and each is trying to SELECT FOR UPDATE the same row (and maybe throwing NOWAIT in there, then catching the errors and retrying), and things slow down.

On top of that, they have to actually update the row to mark it as locked, so the rest of your workers are sitting there waiting while one of them propagates its lock to disk (and the disks of however many servers you're replicating to). QueueClassic got some mileage out of the novel idea of randomly picking a row near the front of the queue to lock, but I can't still seem to get more than an an extra few hundred jobs per second out of it under heavy load.

So, many developers have started going straight t

@Austio
Austio / NGINX on Ruby on Rails with Unicorn and GZIP assets
Last active September 3, 2018 19:22
Configure NGINX for SSL using unicorn and gzip assets optimizations
1. Open a command prompt and navigate to /etc/nginx/ssl
2. Issue "openssl req -new -newkey rsa:2048 -nodes -keyout server.key -out server.csr"
3. Get your certificate issued - Go to your certificate authority and give them the CSR (server.csr)
4. Copy your new crt (that the certificate authority issued) to the /etc/nginx/ssl and give it read priveledges
5. Reconfigure your nginx.conf, here is mine. The first part redirects 80 to 443, the second part listens to 443 and is optimized to return Ruby on Rails application requests using gzip and unicorn.
@return1
return1 / bitcoin-cpuminer.sh
Last active March 18, 2024 23:23
install a bitcoin cpuminer on ubuntu/debian
# install dependencies
sudo apt-get install libcurl4-openssl-dev libncurses5-dev pkg-config automake yasm
# clone cpuminer
git clone https://github.com/pooler/cpuminer.git
# compile
cd cpuminer
./autogen.sh
./configure CFLAGS="-O3"
@ryanb
ryanb / issues_with_modules.md
Created November 29, 2012 22:38
Points on how modules can make code difficult to read.

My issues with Modules

In researching topics for RailsCasts I often read code in Rails and other gems. This is a great exercise to do. Not only will you pick up some coding tips, but it can help you better understand what makes code readable.

A common practice to organize code in gems is to divide it into modules. When this is done extensively I find it becomes very difficult to read. Before I explain further, a quick detour on instance_eval.

You can find instance_eval used in many DSLs: from routes to state machines. Here's an example from Thinking Sphinx.

class Article < ActiveRecord::Base