Skip to content

Instantly share code, notes, and snippets.

View prdanelli's full-sized avatar
👋

Paul Danelli prdanelli

👋
View GitHub Profile
@prdanelli
prdanelli / gist:2912305
Last active August 16, 2021 10:59
detect screen scrolled at bottom
if($(window).scrollTop() + $(window).height() == $(document).height()) {
}
@prdanelli
prdanelli / module
Created June 11, 2013 16:53
Example JS Module example.
// module...
// encapculates the properties of the function
// returns the function
String.method('deentity', function(){
var entities = {
quote: '"',
lt: '<',
gt: '>'
};
@prdanelli
prdanelli / gist:936b2c4c402b4aca8142
Last active August 16, 2021 10:58
Example of Revealing module pattern in javascript
var myRevealingModule = (function () {
var privateCounter = 0;
function privateFunction() {
privateCounter++;
}
function publicFunction() {
publicIncrement();
@prdanelli
prdanelli / gist:fd07d714c240f06488c6
Last active August 29, 2015 14:06
setting up iptables
iptables -A INPUT -i eth0 -m state --state RELATED,ESTABLISHED -j ACCEPT &&
iptables -A INPUT -p tcp -m tcp --tcp-flags FIN,SYN,RST,PSH,ACK,URG NONE -j DROP &&
iptables -A INPUT -p tcp -m tcp ! --tcp-flags FIN,SYN,RST,ACK SYN -m state --state NEW -j DROP &&
iptables -A INPUT -p tcp -m tcp --tcp-flags FIN,SYN,RST,PSH,ACK,URG FIN,SYN,RST,PSH,ACK,URG -j DROP &&
iptables -A INPUT -i lo -j ACCEPT &&
iptables -A INPUT -p tcp -m tcp --dport 80 -j ACCEPT &&
iptables -A INPUT -p tcp -m tcp --dport 22 -j ACCEPT;
iptables-save > /etc/iptables.rules
iptables-restore < /etc/iptables.rules
@prdanelli
prdanelli / gist:76404ebacb88aced1cbf
Created May 7, 2015 19:34
Get rails sending through mandrill
#app/config/initializers/mailer.rb
ActionMailer::Base.smtp_settings = {
address: 'smtp.mandrillapp.com',
port: 587,
user_name: '<account email>',
password: '<api key>',
authentication: 'login'
}
ActionMailer::Base.delivery_method = :smtp
du -h --max-depth 1
@prdanelli
prdanelli / clear-sidekiq-jobs.rb
Last active May 21, 2021 09:48 — forked from wbotelhos/clear-sidekiq-jobs.sh
Clear Sidekiq Jobs
# Oneliner
require 'sidekiq/api'; [Sidekiq::Queue.all.each(&:clear), Sidekiq::ScheduledSet.new.clear, Sidekiq::RetrySet.new.clear, Sidekiq::DeadSet.
new.clear];
require 'sidekiq/api';
# 1. Clear retry set
Sidekiq::RetrySet.new.clear
# 2. Clear scheduled jobs
@prdanelli
prdanelli / gist:c2cce7c1403488917d16b3f3bbee9fe8
Last active February 1, 2022 13:57
Decorate class with extend/prepend

Decorate class with extend/prepend

Update indexed instance after blob analyzed

# app/jobs/active_storage/analyze_job_decorator.rb
module ActiveStorage::AnalyzeJobDecorator
  def self.prepended(base)
    base.around_perform do |job, block|
      block.call
@prdanelli
prdanelli / gist:47ef0b4e4cc1f7f54bee8e8e629b03b7
Created November 15, 2019 19:19
Module, metaprogramming, dynamic instance/class method definition
# Usage:
# class YourClass < ApplicationRecord
# denormalizable_collection :my_collection
# ...
#
# def self.my_collection_data
# self.where(...).limit(5)
# end
# end
@prdanelli
prdanelli / gist:d4c5511ca4b38ff1c1211331228f6586
Created January 7, 2020 12:35
Send email from Rails Console.
options = {
to: "recipient@address.com",
from: "email@address.org",
subject: "Testing",
body: "This is the body"
}
ActionMailer::Base.mail(options).deliver_now