Skip to content

Instantly share code, notes, and snippets.

Tom Winzig winzig

Block or report user

Report or block winzig

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@winzig
winzig / cloudsearch-clone-domain.sh
Created May 8, 2018
A bash script to help you clone an AWS CloudSearch domain
View cloudsearch-clone-domain.sh
#!/bin/bash
#
# Usage: cloudsearch-clone-domain <domain> <newdomain>
#
# After you run this script, you'll have a file named define-fields-<newdomain>.sh, which
# you can run to re-create all the fields from the cloned domain. If you haven't yet created
# the new CS domain, then run `aws cloudsearch create-domain --domain-name <newdomain>` before
# running the define-fields script that is produced by this script.
die () {
@winzig
winzig / ClientIP.cs
Last active Jan 28, 2019
If you're using a load balancer that obscures the remote client's true IP address, you can run this IHttpModule to take the first IP address from the X-Forwarded-For header, and overwrite the REMOTE_ADDR and REMOTE_HOST server variables. (We tried to use the URL Rewrite module that everyone normally recommends to do this, but it's buggy.)
View ClientIP.cs
using System;
using System.Web;
using System.Text.RegularExpressions;
namespace HttpModules
{
/// <summary>
/// This module handles complications from our load balancer configuration not properly passing the client's true IP
/// address to our code via the REMOTE_ADDR and REMOTE_HOST variables. We tried to use URL Rewrite to compensate for
/// this, but it does not run when default documents are being accessed (a longstanding bug).
@winzig
winzig / FormatList.cs
Last active Oct 15, 2015
A function that can take a list of strings, and return an intelligently formatted string at or below the given max length. And if you don't think it should use an Oxford comma, read this: https://twitter.com/socratic/status/507579515191967744
View FormatList.cs
using System;
using System.Collections.Generic;
namespace Winzig.Text
{
public class Functions
{
/// <summary>
/// Given a List of strings, and a max length for the returned string, return a formatted list like this one for five items:
///
@winzig
winzig / Alamofire+UIImage.swift
Last active Aug 11, 2016
Ray Wenderlich's UIImage serializer for Alamofire, updated for Alamofire 3.0 and Swift 2
View Alamofire+UIImage.swift
extension Alamofire.Request {
/** Response serializer for images from: http://www.raywenderlich.com/85080/beginning-alamofire-tutorial */
public static func imageResponseSerializer() -> ResponseSerializer<UIImage, NSError> {
return ResponseSerializer { request, response, data, error in
guard let validData = data else {
let failureReason = "Data could not be serialized. Input data was nil."
let error = Error.errorWithCode(.DataSerializationFailed, failureReason: failureReason)
return .Failure(error)
@winzig
winzig / Liberal Regex Pattern for URLs
Last active Jun 23, 2019 — forked from gruber/Liberal Regex Pattern for Web URLs
Updated @gruber's regex with a modified version that looks for 2-13 letters rather than trying to look for specific TLDs, and many other improvements. (UPDATE 2018-07-30: Support for IPv4 addresses, bare hostnames, naked domains, xn-- internationalized domains, and more... see comments for BREAKING CHANGE.)
View Liberal Regex Pattern for URLs
# Single-line version:
(?i)\b(https?:\/{1,3})?((?:(?:[\w.\-]+\.(?:[a-z]{2,13})|(?<=http:\/\/|https:\/\/)[\w.\-]+)\/)(?:[^\s()<>{}\[\]]+|\([^\s()]*?\([^\s()]+\)[^\s()]*?\)|\([^\s]+?\))+(?:\([^\s()]*?\([^\s()]+\)[^\s()]*?\)|\([^\s]+?\)|[^\s`!()\[\]{};:'\".,<>?«»“”‘’])|(?:(?<!@)(?:\w+(?:[.\-]+\w+)*\.(?:[a-z]{2,13})|(?:(?:[0-9](?!\d)|[1-9][0-9](?!\d)|1[0-9]{2}(?!\d)|2[0-4][0-9](?!\d)|25[0-5](?!\d))[.]?){4})\b\/?(?!@)(?:[^\s()<>{}\[\]]+|\([^\s()]*?\([^\s()]+\)[^\s()]*?\)|\([^\s]+?\))*(?:\([^\s()]*?\([^\s()]+\)[^\s()]*?\)|\([^\s]+?\)|[^\s`!()\[\]{};:'\".,<>?«»“”‘’])?))
# Commented multi-line version:
(?xi)
\b
(https?:\/{1,3})? # Capture $1: (optional) URL scheme, colon, and slashes
( # Capture $2: Entire matched URL (other than optional protocol://)
You can’t perform that action at this time.