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
@equivalent
equivalent / add_ip.sh
Created September 29, 2017 16:54
AWS EC2 security group add current IP and remove old IP
myip=$(dig +short myip.opendns.com @resolver1.opendns.com) # this will fetch my current IP
#myip=$(curl -s checkip.dyndns.org|sed -e 's/.*Current IP Address: //' -e 's/<.*$//')
mkdir -p "./tmp"
touch "./tmp/old_ip.txt"
removing_ip=$(cat ./tmp/old_ip.txt)
adding_ip=$myip
echo $adding_ip > ./tmp/old_ip.txt
@equivalent
equivalent / elasticsearch-refresh.md
Last active November 3, 2016 14:34
how to tell elasticsearch to sync (refresh) data indeterminately in order to search it
@equivalent
equivalent / default.conf
Created October 3, 2016 22:39
Nginx example of using CORS
upstream mycoolapp {
server unix:///var/run/puma.sock;
}
server {
listen 80;
server_name www.my-cool-website.com;
return 301 https://$host$request_uri;
}
@equivalent
equivalent / enumerables_enumerators_and_lazynes.rb
Last active August 4, 2016 18:23
Enumerables Enumerators, Lazynes and domain specific collections
#require 'pry' # pry gem for debugging
require 'forwardable' # core ruby lib.
# Don't mind this module, it's just for formating output of examples
module Article
def self.h1(title)
extended_title = "###### #{title} ######"
puts "\n\n\n#{extended_title}\n"
puts "=" * extended_title.length
end
@equivalent
equivalent / rails-enumerable_spec.rb
Created July 11, 2016 10:34
how to include Enumerable in Rails in order to have `blank?` functionality
require 'active_support/core_ext/module/delegation'
require 'active_support/core_ext/object/blank'
require 'rspec'
class Membership
class MembershipCollection
include Enumerable
delegate :empty?, :each, to: :@members
@equivalent
equivalent / rspec-be-within-matcher.rb
Last active September 13, 2023 20:27
Several examples how to use Ruby RSpec 3 `be_within` matcher for delta compare
require 'rspec'
require 'time'
require 'active_support/time'
class Foo
def float_range_example
33 * 5 * Math::PI
end
def time_range
require 'ansi'
require 'sqlite3'
require 'active_record'
require 'elasticsearch/model'
require 'paperclip'
require "paperclip/railtie"
Paperclip::Railtie.insert
ActiveRecord::Base.logger = ActiveSupport::Logger.new(STDOUT)
@equivalent
equivalent / activerecord_mapping_edge_ngram.rb
Last active August 9, 2022 17:39
ActiveRecord Elasticsearch edge ngram example for Elasticsearch gem Rails
require 'ansi'
require 'sqlite3'
require 'active_record'
require 'elasticsearch/model'
ActiveRecord::Base.logger = ActiveSupport::Logger.new(STDOUT)
ActiveRecord::Base.establish_connection( adapter: 'sqlite3', database: ":memory:" )
ActiveRecord::Schema.define(version: 1) do
create_table :articles do |t|
@equivalent
equivalent / gist:b492f6779e99ee9defb2
Created March 23, 2016 23:54
Ruby AES Encryption using OpenSSL
#!/usr/bin/env ruby
require "openssl"
require 'digest/sha2'
require 'base64'
# We use the AES 256 bit cipher-block chaining symetric encryption
alg = "AES-256-CBC"
# We want a 256 bit key symetric key based on some passphrase
digest = Digest::SHA256.new
@equivalent
equivalent / 1_rebinding_module_method.rb
Last active August 29, 2015 14:26
Rebind module method example
# run me with ruby >= 2.0
module A
def x(arg)
"hi #{arg}"
end
end
module B
def x(arg)