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 / README.md
Last active April 8, 2024 03:00
Rails 7 importmaps dropzone.js direct upload ActiveStorage

This is simple implementation of technologies in hobby project of mine built in Rails7 where I need direct upload to S3.

@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
@equivalent
equivalent / list_all_rails_models.rb
Created November 8, 2011 13:03
how to get model names of all rails models (works for STI)
#Since Rails doesn't load classes unless it needs them, you must read the models from the folder. Here is the code
Dir[Rails.root.to_s + '/app/models/**/*.rb'].each do |file|
begin
require file
rescue
end
end
models = ActiveRecord::Base.subclasses.collect { |type| type.name }.sort
@equivalent
equivalent / app-assets-javascript-datepicker.js.coffee
Created July 5, 2012 12:24
Simple Form custom input for "Datepicker for Twitter Bootstrap" running under Ruby on Rails with Ransack search
# install and make run basic bootstrap date-picker functionality described here http://www.eyecon.ro/bootstrap-datepicker/
# app/assets/javascript/datepicker.js.coffee
$(document).on 'pageChanged', ->
# datepicker for simple_form & Ransack
$(".custom_datepicker_selector").datepicker().on 'changeDate', (en) ->
correct_format = en.date.getFullYear() + '-' + ('0' + (en.date.getMonth() + 1)).slice(-2) + '-' + ('0' + en.date.getDate()).slice(-2) # date format yyyy-mm-dd
$(this).parent().find("input[type=hidden]").val(correct_format)
@equivalent
equivalent / csv_generate.rb
Created January 5, 2023 13:09
how to generare CSV for milion records in sidekiq
Model.pluck(:id, :name, ...).find_in_batches(10_000) do |ary|
CSV.open("tmp.csv", "ab") do |csv|
csv << ary.map{|a| a.join ','}.join("\n")
end
end
@equivalent
equivalent / README.md
Last active September 29, 2022 13:26
Hubspot CRM API Delete a secondary email address

Hubspot CRM API Delete a secondary email address

how to delete secondary email from a Contact in Hubspot CRM via a API

@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|
# why and what is solarized http://ethanschoonover.com/solarized
# Simple installation notes for iterm2 and Solarized
Set ZSH_THEME in ~/.zshrc to blinks
https://github.com/altercation/solarized/tree/master/iterm2-colors-solarized
#if you create new profile e.g. solarized you have to set him as default
#Simple installation notes for janus and Solarized
# .vimrc.before
let g:solarized_termcolors=256
set t_Co=16
@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 / README.md
Last active December 16, 2021 16:34
String "false" to_bool ... or how to convert Rails/SimpleForm radio buttons to boolean

This gist was writen in 2012 and it was solving specific problem in Rails & SimpleForm. Some fellow developers were pointing out this may be out dated concept. That's why I advise everyone to read comment section bellow to have a full grasp of alternative solutions

other sources that may be helpful to understand why this may not be best idea: