Skip to content

Instantly share code, notes, and snippets.

@j-a4
j-a4 / email_mx_validator.rb
Last active May 25, 2018 19:23
Email MX validator for Mastodon
# Validates that MX record exists for domain to prevent typos and also block by MX servers
# Use by adding to app/models/user.rb
# validates_with EmailMXValidator, if: :email_changed?
# frozen_string_literal: true
require 'resolv'
class EmailMXValidator < ActiveModel::Validator
def validate(user)
domain = user.email.split('@', 2).last
mxs = Resolv::DNS.new.getresources(domain, Resolv::DNS::Resource::IN::MX).to_a.map { |e| e.exchange.to_s }
@letsar
letsar / variable_sized_grid_view.dart
Last active January 31, 2023 22:54
VariableSizedGridView for Flutter (Masonry style)
import 'dart:math' as math;
import 'package:flutter/foundation.dart';
import 'package:flutter/rendering.dart';
import 'package:flutter/widgets.dart';
/// Signature for a function that creates a [TileSize] for a given index.
typedef TileSize IndexedTileSizeBuilder(int index);
/// Creates grid layouts with a fixed number of spans in the cross axis.
// Paste the code below into the JavaScript console while logged in to CloudPebble for
// a link to a zip file containing all your CloudPebble projects.
console.log("Requesting export...");
Ajax.Post('/ide/transition/export', {}).then(function(data) {
console.log("Request result: ");
console.log(data);
console.log("Waiting for archive. This may take a long time.");
return Ajax.PollTask(data.task_id, {on_bad_request: console.error});
}).then(function(result) {
@jeandrek
jeandrek / tpe-alt-alt.user.js
Last active December 6, 2015 22:18 — forked from hyperobject/tpe-alt.user.js
A remixed remixed TPE userscript
// ==UserScript==
// @name thisandagain Summoner
// @namespace thisandagainPlsExplainThisPost
// @version 1.06
// @description Adds a button to posts to magically summon thisandagain or thisandbatman
// @author Jonathan50
// @match https://scratch.mit.edu/discuss/*
// @grant none
// ==/UserScript==
@enjalot
enjalot / cors_server.py
Created June 10, 2012 06:19
Allow CORS with python simple http server
import SimpleHTTPServer
class CORSHTTPRequestHandler(SimpleHTTPServer.SimpleHTTPRequestHandler):
def send_head(self):
"""Common code for GET and HEAD commands.
This sends the response code and MIME headers.
Return value is either a file object (which has to be copied
to the outputfile by the caller unless the command was HEAD,
and must be closed by the caller under all circumstances), or