Skip to content

Instantly share code, notes, and snippets.

View ka8725's full-sized avatar
๐Ÿš€
Building Web and Mobile apps

Andrei Kaleshka ka8725

๐Ÿš€
Building Web and Mobile apps
View GitHub Profile
@0x000000
0x000000 / gist:3852426
Created October 8, 2012 13:07
ะกะฟะธัะพะบ ััั‹ะปะพะบ ะดะปั RubyGardens
=== ะงะฐัั‚ัŒ 1. ะžะฑะทะพั€ะฝะฐั ะธะฝั„ะพั€ะผะฐั†ะธั
== ะžะฑัะทะฐั‚ะตะปัŒะฝะพ ะฟะพัะผะพั‚ั€ะธั‚ะต
http://en.wikipedia.org/wiki/Internet_media_type
http://en.wikipedia.org/wiki/List_of_HTTP_status_codes ะธะปะธ http://www.flickr.com/photos/girliemac/sets/72157628409467125
http://api.rubyonrails.org/classes/ActionDispatch/Response.html
http://api.rubyonrails.org/classes/ActionDispatch/Request.html
== ะ”ะพะบัƒะผะตะฝั‚ะฐั†ะธั ะฟะพ AJAX ะฒ jQuery
@ka8725
ka8725 / gist:3892048
Created October 15, 2012 11:39 — forked from 0x000000/gist:3852426
ะกะฟะธัะพะบ ััั‹ะปะพะบ ะดะปั RubyGardens
=== ะงะฐัั‚ัŒ 1. ะžะฑะทะพั€ะฝะฐั ะธะฝั„ะพั€ะผะฐั†ะธั
== ะžะฑัะทะฐั‚ะตะปัŒะฝะพ ะฟะพัะผะพั‚ั€ะธั‚ะต
http://en.wikipedia.org/wiki/Internet_media_type
http://en.wikipedia.org/wiki/List_of_HTTP_status_codes ะธะปะธ http://www.flickr.com/photos/girliemac/sets/72157628409467125
http://api.rubyonrails.org/classes/ActionDispatch/Response.html
http://api.rubyonrails.org/classes/ActionDispatch/Request.html
== ะ”ะพะบัƒะผะตะฝั‚ะฐั†ะธั ะฟะพ AJAX ะฒ jQuery
@Odaeus
Odaeus / application_controller.rb
Last active February 12, 2025 06:24
Alternative to Rails' sharing of instance variables between controller and views.
class ApplicationController < ActionController::Base
# Creates an accessor which is exposed to the view
def self.view_accessor(*names)
attr_accessor *names
helper_method *names
end
end
@jswanner
jswanner / migrate.rake
Last active August 15, 2024 15:15
Rolls back migrations in current branch not present in specified branch.
desc 'rolls back migrations in current branch not present in other'
task :rollback_branch_migrations, [:other_branch] do |t, args|
load "#{Dir.pwd}/Rakefile"
branch_migrations = BranchMigrations.new(args.other_branch)
puts ['Rollback the following migrations', branch_migrations, 'y,n? ']
next if %w[no n NO N].include?(STDIN.gets.chomp)
Rake::Task['environment'].invoke
@wteuber
wteuber / encrypt_decrypt.rb
Last active February 2, 2026 15:13
Basic encrypt and decrypt Strings in Ruby with deterministic salt or IV, generate and store random salt and IV in production
require 'openssl'
class String
CIPHER_NAME = 'aes-256-cbc'.freeze
PBKDF_ITER = 200_000
KEY_LEN = 32 # 256 bits
SALT_CONST = "fixed-global-salt-v1".freeze
IV_SALT_CONST = "fixed-iv-salt-v1".freeze
def encrypt(password)
@iboard
iboard / ruby-destructor-example.rb
Last active March 21, 2025 09:32
Ruby 'Destructor' example.
class Foo
attr_reader :bar
def initialize
@bar = 123
ObjectSpace.define_finalizer( self, self.class.finalize(bar) )
end
def self.finalize(bar)
proc { puts "DESTROY OBJECT #{bar}" }
end
class Runner
def run(&block)
begin
instance_exec(&block)
@on_success.call if @on_success
rescue Exception => ex
@on_failure.call(ex) if @on_failure
end
end
@matthewrobertson
matthewrobertson / base_serializer.rb
Last active June 14, 2016 07:16
A simple pattern for creating classes that encapsulate JSON serialization logic. Simply inherit from the `BaseSerializer` and override the hook methods as necessary.
# An abstract base class used to create simple serializers
# for ActiveRecord objects
class BaseSerializer
include Rails.application.routes.url_helpers
attr_reader :serialized_object
def initialize(serialized_object)
@serialized_object = serialized_object
end
@maxim
maxim / rails_load_path_tips.md
Last active January 9, 2025 00:59
How to use rails load paths, app, and lib directories.

In Rails 3

NOTE: This post now lives (and kept up to date) on my blog: http://hakunin.com/rails3-load-paths

If you add a dir directly under app/

Do nothing. All files in this dir are eager loaded in production and lazy loaded in development by default.

If you add a dir under app/something/

@tzvetkoff
tzvetkoff / gist:7287456
Last active January 8, 2019 06:44
Make it more test-ish
unless File.exist?('Gemfile')
File.write('Gemfile', <<-GEMFILE)
source 'https://rubygems.org'
gem 'rails', :github => 'rails/rails'
gem 'sqlite3'
GEMFILE
system 'bundle'
end