Skip to content

Instantly share code, notes, and snippets.

View danielpuglisi's full-sized avatar
💭
🤘

Daniel Puglisi danielpuglisi

💭
🤘
View GitHub Profile
@chrisbodhi
chrisbodhi / copy.rb
Created September 21, 2016 14:25
Copy from IRB/Pry to the system clipboard
# https://coderwall.com/p/qp2aha/ruby-pbcopy-and-pbpaste
def pbcopy(input)
str = input.to_s
IO.popen('pbcopy', 'w') { |f| f << str }
str
end
@ericboehs
ericboehs / icloud-caldav.rb
Last active June 30, 2021 10:27
Interface with Apple's iCloud CalDav Calendars
require 'rexml/document'
require 'rexml/xpath'
require 'http'
require 'icalendar'
HTTP::Request::METHODS = HTTP::Request::METHODS + [:report]
module AppleCalDav
class Client
attr_accessor :username, :password
@jarednorman
jarednorman / webpack-rails-1.markdown
Last active May 13, 2020 18:24
Webpack with Rails Part 1

Webpack with Rails Part 1

I don't like Sprockets, but it's the easiest and best choice for lots of Ruby on Rails projects. When looking for a better way to manage my JavaScript assets and an improved developer story, my current tool of choice is webpack. While I wish Rails supported drop-in asset pipelines the way that Phoenix does, it's not hard to use webpack with Rails.

@matiaskorhonen
matiaskorhonen / check-certificate.rb
Last active April 19, 2021 21:53
Check an SSL/TLS certificate in Ruby (with SNI support)
# Modified from:
# http://findingscience.com/ruby/ssl/2013/01/13/reading-an-ssl-cert-in-ruby.html
require "socket"
require "openssl"
host = "www.piranhas.co"
tcp_client = TCPSocket.new("www.piranhas.co", 443)
ssl_client = OpenSSL::SSL::SSLSocket.new(tcp_client)
@colszowka
colszowka / dns_check.rb
Last active October 12, 2022 10:39
Ruby DNS Check
require 'resolv'
class DnsCheck
attr_reader :host
def initialize(host)
@host = host
end
def a
@a ||= Resolv::DNS.new.getresources(host, Resolv::DNS::Resource::IN::A)
@jaimeiniesta
jaimeiniesta / setup_sumo_me.js.coffee
Created December 21, 2014 15:48
How to load SumoMe script in a turbolinks-friendly way
# Defines a namespace for my application
MyApplication = {}
# A way to pass a callback both to jQuery's "ready" and turbolinks' "page:load" events
MyApplication.onDocumentReady = (callback) ->
$(document).ready(callback)
$(document).on('page:load', callback)
# Defines a function to load the SumoMe script
MyApplication.load_sumome_script = (data_sumo_site_id) ->
@henrik
henrik / using_string_range.rb
Last active July 12, 2019 08:18
Is a given time in a time range, in Ruby?
# Note: upper bound is 12:01:59 (you could use second precision to get around this, e.g. "12:01:00")
time = Time.mktime(2014, 10, 14, 12, 1)
allowed_ranges = [
"11:59".."12:01",
]
formatted_time = time.strftime("%H:%M")
p allowed_ranges.any? { |range| range.cover?(formatted_time) }
@jvenezia
jvenezia / rails_mailer_structure.md
Last active January 4, 2023 13:44
Rails mailer structure

Rails mailer structure

Your application is growing, and you are starting to have a complex mailing system: notification emails, retention emails, misc user emails, admin emails, etc...

It's time to clean up your mailers !

Existing mailer

You may already have a single mailer, responsible of every emails, like this one:

@remino
remino / compression.rb
Created September 3, 2014 03:58
Ruby on Rails: Minify HTML, CSS, & JS, and compress with gzip https://remino.net/rails-html-css-js-gzip-compression/
# config/initializers/compression.rb
Rails.application.configure do
# Use environment names or environment variables:
# break unless Rails.env.production?
break unless ENV['ENABLE_COMPRESSION'] == '1'
# Strip all comments from JavaScript files, even copyright notices.
# By doing so, you are legally required to acknowledge
# the use of the software somewhere in your Web site or app:
@krisbulman
krisbulman / countCSSRules.js
Last active August 25, 2022 19:53 — forked from psebborn/countCSSRules.js
Count the number of rules and selectors for CSS files on the page. Flags up the >4096 threshold that confuses IE. — This snippet has been modified to count more than just the first level of CSSStyleRule objects within CSSMediaRule.
function countCSSRules() {
var results = '',
log = '';
if (!document.styleSheets) {
return;
}
for (var i = 0; i < document.styleSheets.length; i++) {
countSheet(document.styleSheets[i]);
}
function countSheet(sheet) {