Skip to content

Instantly share code, notes, and snippets.

View ritec's full-sized avatar

Ri Caragol ritec

View GitHub Profile
@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 / 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 / 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 / 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 / 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 / user_agent.sql
Created January 11, 2018 22:12
New Relic Percentage User Agent
select percentage(uniquecount(session), where userAgentName = 'Chrome') as 'Chrome', percentage(uniquecount(session), where userAgentName = 'Firefox') as 'FireFox', percentage(uniquecount(session), WHERE userAgentName='IE') as 'IE' , percentage(uniquecount(session), WHERE userAgentName ='Safari') as 'Safari' from PageView SINCE 600 minutes ago
@ritec
ritec / bench_rails_memory_usage.rb
Created December 10, 2017 21:24 — forked from brianhempel/bench_rails_memory_usage.rb
A script to test the memory usage of your Rails application over time. It will run 30 requests against the specified action and report the final RSS. Choose the URL to hit on line 45 and then run with `ruby bench_rails_memory_usage.rb`.
require "net/http"
def start_server
# Remove the X to enable the parameters for tuning.
# These are the default values as of Ruby 2.2.0.
@child = spawn(<<-EOC.split.join(" "))
XRUBY_GC_HEAP_FREE_SLOTS=4096
XRUBY_GC_HEAP_INIT_SLOTS=10000
XRUBY_GC_HEAP_GROWTH_FACTOR=1.8
XRUBY_GC_HEAP_GROWTH_MAX_SLOTS=0
require 'fileutils'
namespace :spec do
def progress name, x, y
print "\r #{name}: #{x}/#{y} %6.2f%%" % [x.to_f/y * 100]
end
def generate_files name
kind = name.to_s.singularize
collection = Dir.glob Rails.root.join('app',name.to_s,'**','*').to_s
@ritec
ritec / Git Trips and Tricks
Created June 23, 2017 14:24
Git tips and tricks
# Delete many branches with one command
git branch | grep 'NXT-7' | xargs git branch -d
@ritec
ritec / zipToCityState.js
Created November 7, 2016 15:16
Get City and State from Zip Code with Google Geo API
window.findAddressFromZip = function(zipcode) {
var city, state, zip;
zip = zipcode.value;
city = '';
state = '';
if (zip.length === 5) {
$.ajax({
type: 'POST',
url: "http://maps.googleapis.com/maps/api/geocode/json?address=" + zip + "?key=XXXXXXXXXXXXXXXXXXXX",
success: (function(_this) {