Skip to content

Instantly share code, notes, and snippets.

View udiudi's full-sized avatar
🏠
Working from home

Udi udiudi

🏠
Working from home
View GitHub Profile
# Rails production setup via SQLite3 made durable by https://litestream.io/
# Copy this to Dockerfile on a fresh rails app. Deploy to fly.io or any other container engine.
#
# try locally: docker build . -t rails && docker run -p3000:3000 -it rails
#
# in production you might want to map /data to somewhere on the host,
# but you don't have to!
#
FROM ruby:3.0.2
@nateberkopec
nateberkopec / correction.md
Last active February 14, 2024 16:22
A Simple Correction

In yesterday's post I said, in relation to "how does .present? work on ActiveRecord::Relation", I said that present? performs an existence check SELECT 1 AS one FROM ... LIMIT 1 because it calls exists? underneath. This is actually wrong - it loads the relation.

Jonathan Mast corrected me on Twitter. It turns out, I should have paid closer attention! Here is the actual implementation of blank? on ActiveRecord::Relation on Rails master:

# Returns true if relation is blank.
def blank?
  records.blank?
end
[core]
excludesfile = ~/.gitignore_global
pager = diff-so-fancy | less --tabs=4 -RFX
[difftool "sourcetree"]
cmd = opendiff \"$LOCAL\" \"$REMOTE\"
path =
[alias]
aa = add --all
@alekseykulikov
alekseykulikov / index.md
Last active April 14, 2024 00:32
Principles we use to write CSS for modern browsers

Recently CSS has got a lot of negativity. But I would like to defend it and show, that with good naming convention CSS works pretty well.

My 3 developers team has just developed React.js application with 7668 lines of CSS (and just 2 !important). During one year of development we had 0 issues with CSS. No refactoring typos, no style leaks, no performance problems, possibly, it is the most stable part of our application.

Here are main principles we use to write CSS for modern (IE11+) browsers:

@derwiki
derwiki / README.md
Last active September 27, 2023 17:50
Ruby module that you can use in a `before_action` on sensitive controllers for which you'd like a usage audit trail

Adding an audit log to your Rails app

If you have any sort of administrative interface on your web site, you can easily imagine an intruder gaining access and mucking about. How do you know the extent of the damage? Adding an audit log to your app is one quick solution. An audit log should record a few things:

  • controller entry points with parameter values
  • permanent information about the user, like user_id
  • transient information about the user, like IP and user_agent

Using the Rails framework, this is as simple as adding a before_action to your admin controllers. Here’s a basic version that I’m using in production.

@wr0ngway
wr0ngway / rubytrace
Last active March 14, 2023 11:02
Uses gdb to dump ruby backtraces for all threads, and displays them in an easily readable format
#!/bin/bash
PID=$1
RUBY_BINARY=`which ruby`
BT_FILENAME="/tmp/ruby-backtrace-$PID-$(date +%s).txt"
cmdfile=$(mktemp)
cat <<EOF > $cmdfile
set \$old_stdout = dup(1)
set \$old_stderr = dup(2)
@emaraschio
emaraschio / SOLID.markdown
Last active May 24, 2023 07:18
SOLID Principles with ruby examples

#SOLID Principles with ruby examples

##SRP - Single responsibility principle A class should have only a single responsibility.

Every class should have a single responsibility, and that responsibility should be entirely encapsulated. All its services should be narrowly aligned with that responsibility, this embrace the high cohesion.

##OCP - Open/closed principle Software entities should be open for extension, but closed for modification.

{
"query": {
"function_score": {
"query": {
"bool": {
"must": {
"multi_match": {"query": "Renaissance", "fields": ["name", "company"]},
"term": {"features": "disability_access"},
},
"should": {
@dhoelzgen
dhoelzgen / base_controller.rb
Last active October 7, 2021 16:19
CORS in Rails 4 APIs
class API::V1::BaseController < ApplicationController
skip_before_filter :verify_authenticity_token
before_filter :cors_preflight_check
after_filter :cors_set_access_control_headers
def cors_set_access_control_headers
headers['Access-Control-Allow-Origin'] = '*'
headers['Access-Control-Allow-Methods'] = 'POST, GET, PUT, DELETE, OPTIONS'
@kennethgunn
kennethgunn / v8_log_processing.md
Created September 30, 2013 21:36
How to process a V8 profiling log file

FIGURE OUT THE RIGHT V8 VERSION

  • check your node version (if you use nvm, the version will be in the path in the first line of v8.log)
  • open https://github.com/joyent/node/blob/master/deps/v8/ChangeLog
  • click the "branch: master" drop down
  • click "tags"
  • choose the proper version (e.g. v0.10.15)
  • version should be listed in top line (e.g., 3.14.5)

GET THE CORRECT LOG PROCESSOR