Skip to content

Instantly share code, notes, and snippets.

View ljuti's full-sized avatar
💻
Most likely in an editor

Lauri Jutila ljuti

💻
Most likely in an editor
View GitHub Profile
@ljuti
ljuti / mx_resolver.py
Created January 4, 2024 20:21
MX Record Resolver for Email Provider
## MX Record Resolver for Email Provider
#
# This script takes a CSV file with a column of email addresses and adds a column
# with the email provider (e.g. Google, Microsoft, etc.) based on the MX record
# of the email address domain.
#
# The MX record is the DNS record that specifies the mail server responsible for
# accepting email messages on behalf of a domain name. The MX record is used to
# route email messages to the correct mail server.
#
require "CrSerializer"
register_assertion CrSerializer::Assertions::Matches, [ :matcher ]
register_assertion CrSerializer::Assertions::ValidURI, [] of Symbol
register_assertion CrSerializer::Assertions::ExpectValid, [] of Symbol
register_assertion CrSerializer::Assertions::ValidEmail, [] of Symbol
register_assertion CrSerializer::Assertions::IFTTT, [ :property, :ruleset ] of Symbol
module CrSerializer::Assertions
class MatchesAssertion(ActualValueType) < CrSerializer::Assertions::Assertion
@ljuti
ljuti / bug_upcasting.cr
Last active October 21, 2018 19:30
Code to reproduce an upcasting compiler bug with Crystal 0.26.1
module A
abstract struct BaseFactory
alias ValidContextTypes = A::Context
def initialize(@context : ValidContextTypes)
end
end
end
module A
@ljuti
ljuti / gist:801948
Created January 29, 2011 16:03 — forked from jcxplorer/gist:794929
bashrc for RVM use
# ~/.bashrc: executed by bash(1) for non-login shells.
# see /usr/share/doc/bash/examples/startup-files (in the package bash-doc)
# for examples
# If not running interactively, don't do anything
if [[ -n "$PS1" ]]; then
# don't put duplicate lines in the history. See bash(1) for more options
# ... or force ignoredups and ignorespace
HISTCONTROL=ignoredups:ignorespace
@ljuti
ljuti / carrierwave.rake
Created January 13, 2011 12:26
CarrierWave rake task to reprocess images for an object
# CarrierWave rake tasks
#
# Task: reprocess
# Desc: Reprocess all images for a given class
# Usage: rake carrierwave:reprocess class=<ClassName> mount_uploader=<mount_uploader>
namespace :carrierwave do
task :reprocess, [:class, :mount_uploader] => :environment do |task, args|
desc "Reprocess all images for a given class."
args[:class].constantize.all.each do |object|
# for Entries#create
Pusher['live'].trigger('entry-posted', render_to_string("entries/push", :layout => false))
# for Images#create
Pusher['live'].trigger('image-posted', render_to_string("images/push", :layout => false))
server.bind('entry-posted', function(entry) {
$("#entries").prepend(entry);
$("#entries div.entry:first").fadeIn();
});
server.bind('image-posted', function(image) {
addImage(image);
});
server.bind('entry-removed', function(entry) {
$("#entries #entry-" + entry).remove();
});
module AttrLogger
def self.included(base)
base.extend ClassLevelMethods
end
module ClassLevelMethods
def attr_logger(*args)
args.each { |attribute|
define_method(attribute) do
value = instance_variable_get("@#{attribute}")
class AttrObject
def self.attr_logger(*args)
args.each { |attribute| define_method(attribute) {
value = instance_variable_get("@#{attribute}")
STDERR.puts "#{Time.now} - #{value}"
}}
end
end