Skip to content

Instantly share code, notes, and snippets.

View ritec's full-sized avatar

Ri Caragol ritec

View GitHub Profile
@ritec
ritec / sidekiq_monitoring
Created February 28, 2018 16:45 — forked from ngsmrk/sidekiq_monitoring
Sidekiq queue checking via rails console
stats = Sidekiq::Stats.new
stats.queues
stats.enqueued
stats.processed
stats.failed
@ritec
ritec / 01_thread.rb
Created March 8, 2018 01:58 — forked from rsim/01_thread.rb
Code examples from my "Using threads in Ruby applications" presentation in our local Ruby meetup http://www.meetup.com/ruby-on-rails-latvia/events/105142132/
Thread.new do
sleep 5
puts "finished"
end
thread = Thread.new do
sleep 5
puts "finished"
end
thread.join
@ritec
ritec / Postgres info
Last active March 8, 2018 19:47
usefulPostgresInfo.sql
# Get a DB Console.
bundle exec rails dbconsole
# Get number of Connections / Used and left
select max_conn,used,res_for_super,max_conn-used-res_for_super res_for_normal
from
(select count(*) used from pg_stat_activity) t1,
(select setting::int res_for_super from pg_settings where name=$$superuser_reserved_connections$$) t2,
(select setting::int max_conn from pg_settings where name=$$max_connections$$) t3
@ritec
ritec / harlem_shake.js
Created August 20, 2018 20:10
Harlem Shake XSS
javascript:(function(){function c(){var e=document.createElement("link");e.setAttribute("type","text/css");e.setAttribute("rel","stylesheet");e.setAttribute("href",f);e.setAttribute("class",l);document.body.appendChild(e)}function h(){var e=document.getElementsByClassName(l);for(var t=0;t<e.length;t++){document.body.removeChild(e[t])}}function p(){var e=document.createElement("div");e.setAttribute("class",a);document.body.appendChild(e);setTimeout(function(){document.body.removeChild(e)},100)}function d(e){return{height:e.offsetHeight,width:e.offsetWidth}}function v(i){var s=d(i);return s.height>e&&s.height<n&&s.width>t&&s.width<r}function m(e){var t=e;var n=0;while(!!t){n+=t.offsetTop;t=t.offsetParent}return n}function g(){var e=document.documentElement;if(!!window.innerWidth){return window.innerHeight}else if(e&&!isNaN(e.clientHeight)){return e.clientHeight}return 0}function y(){if(window.pageYOffset){return window.pageYOffset}return Math.max(document.documentElement.scrollTop,document.body.scrollTop)}funct
@ritec
ritec / libreadline_6_not_found.sh
Last active March 25, 2019 20:58 — forked from wbotelhos/libreadline_6_not_found.sh
Library not loaded: /usr/local/opt/readline/lib/libreadline.7.dylib (LoadError)
ln -s /usr/local/opt/readline/lib/libreadline.7.0.dylib /usr/local/opt/readline/lib/libreadline.6.dylib
# or if the error is with dyld: Library not loaded: /usr/local/opt/readline/lib/libreadline.7.dylib
ln -s /usr/local/opt/readline/lib/libreadline.8.0.dylib /usr/local/opt/readline/lib/libreadline.7.dylib
@ritec
ritec / import_job.rb
Created June 4, 2019 18:07 — forked from madebydna/import_job.rb
Nested Batch workflow with Sidekiq Pro
class ImportJob
include Sidekiq::Worker
sidekiq_options :queue => :import, :retry => false, :backtrace => true
def perform(project_id)
# create master batch
a = Sidekiq::Batch.new
a.description = "Master Batch A"
a.on(:success, "ImportJob#on_success", {"step" => "a"})
logger.info "Master Batch A starting #{a.bid}"
@ritec
ritec / blank.html
Created September 30, 2019 19:51 — forked from geetarista/blank.html
Blank favicon
<link href="data:image/x-icon;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQEAYAAABPYyMiAAAABmJLR0T///////8JWPfcAAAACXBIWXMAAABIAAAASABGyWs+AAAAF0lEQVRIx2NgGAWjYBSMglEwCkbBSAcACBAAAeaR9cIAAAAASUVORK5CYII=" rel="icon" type="image/x-icon" />
@ritec
ritec / Performance
Created January 9, 2020 21:58
Some Ruby on Rails Performance measuring tools
https://github.com/SamSaffron/memory_profiler
https://github.com/schneems/get_process_mem
https://github.com/ruby-prof/ruby-prof
https://ruby-prof.github.io/
@ritec
ritec / drum_sampler_samples_converter.sh
Last active August 24, 2020 14:29
Change format of Audio for Erica Synths Drum Sampler
rmdir ../temp #if there's a temp dir, let's remove it
mkdir ../temp #now make a new temp dir
find . -type d -print0 | while read -d $'\0' subdir; #find all subdirectories
do echo $subdir; mkdir ../temp/${subdir// /}; #and recreate them in the temp dir
done
find . -name "*.wav" -print0 | while read -d $'\0' file; #find all *.wav files to convert
do echo $file; # for each file found
/Users/rcaragol/Downloads/sox-14.4.2/sox -G "$file" --norm=-1 -b 16 -r 48k -c 1 ../temp/${file// /}; #convert to temp directory and remove spaces from filename
done
@ritec
ritec / model.rb
Created July 30, 2021 20:24 — forked from aaronsakowski/model.rb
Searchkick autocomplete by token
searchkick autocomplete: ["name"],
settings: {
analysis: {
analyzer: {
searchkick_keyword: {
type: "custom",
tokenizer: "keyword",
filter: ["lowercase", "snowball"]
},
default_index: {