Skip to content

Instantly share code, notes, and snippets.

@sdrew
sdrew / README-setup-tunnel-as-systemd-service.md
Created January 22, 2018 18:45 — forked from drmalex07/README-setup-tunnel-as-systemd-service.md
Setup a secure (SSH) tunnel as a systemd service. #systemd #ssh #ssh-tunnel #ssh-forward

README

Create a template service file at /etc/systemd/system/secure-tunnel@.service. The template parameter will correspond to the name of target host:

[Unit]
Description=Setup a secure tunnel to %I
After=network.target
@sdrew
sdrew / letsencrypt_2017.md
Created November 28, 2017 07:35 — forked from cecilemuller/letsencrypt_2020.md
How to setup Let's Encrypt for Nginx on Ubuntu 16.04 (including IPv6, HTTP/2 and A+ SLL rating)

How to setup Let's Encrypt for Nginx on Ubuntu 16.04 (including IPv6, HTTP/2 and A+ SLL rating)

There are two main modes to run the Let's Encrypt client (called Certbot):

  • Standalone: replaces the webserver to respond to ACME challenges
  • Webroot: needs your webserver to serve challenges from a known folder.

Webroot is better because it doesn't need to replace Nginx (to bind to port 80).

In the following, we're setting up mydomain.com. HTML is served from /var/www/mydomain, and challenges are served from /var/www/letsencrypt.

// UIImage+Alpha.h
// Created by Trevor Harmon on 9/20/09.
// Free for personal or commercial use, with or without modification.
// No warranty is expressed or implied.
// Helper methods for adding an alpha layer to an image
@interface UIImage (Alpha)
- (BOOL)hasAlpha;
- (UIImage *)imageWithAlpha;
- (UIImage *)transparentBorderImage:(NSUInteger)borderSize;
@sdrew
sdrew / flashflush.sh
Last active August 29, 2015 14:23 — forked from 50kudos/flashflush.sh
#!/bin/bash
cat $(find app/assets/stylesheets/ -type f) |
grep -Eo '\.[a-z]+[a-z0-9_-]*' | sort | uniq | sed s/.// |
while read CSS; do
if ! grep -Erqi "([^(remove|has)]class[(:|=|[:space:]*=>[:space:]*)]*\s*[(\"|')]*[-a-z0-9[:space:]]*$CSS|\\.$CSS\b)" app/views/ vendor/assets/ app/assets/javascripts/; then
echo $CSS >> unused.scss;
fi
done
#!/bin/bash
#Alright, so this should automatically convert a given video into a gif called optimized_output.gif
# See here for explanation: https://github.com/lelandbatey/configDebDev/blob/master/helpFiles.txt#L113
ffmpeg -i $1 out%04d.gif # Extracts each frame of the video as a single gif
convert -delay 4 out*.gif anim.gif # Combines all the frames into one very nicely animated gif.
convert -layers Optimize anim.gif optimized_output.gif # Optimizes the gif using imagemagick
# vvvvv Cleans up the leftovers

Description

This simple script will take a picture of a whiteboard and use parts of the ImageMagick library with sane defaults to clean it up tremendously.

The script is here:

#!/bin/bash
convert $1 -morphology Convolve DoG:15,100,0 -negate -normalize -blur 0x1 -channel RBG -level 60%,91%,0.1 $2

Results

@sdrew
sdrew / routes.rb
Created November 29, 2012 20:34 — forked from madrobby/gist:3923148
def set_locale
locale = params[:locale].to_s
if !locale.blank?
cookies[:preferred_lang] = { :value => locale, :expires => 10.years.from_now }
session[:update_lang] = locale # remember preferred setting for this session
else
locale = cookies[:preferred_lang]
end
@sdrew
sdrew / gist:4023545
Created November 6, 2012 08:47 — forked from akisute/gist:1141953
Create an animated gif file from images in iOS
#import <UIKit/UIKit.h>
#import <ImageIO/ImageIO.h>
#import <MobileCoreServices/MobileCoreServices.h>
- (void)exportAnimatedGif
{
UIImage *shacho = [UIImage imageNamed:@"shacho.png"];
UIImage *bucho = [UIImage imageNamed:@"bucho.jpeg"];
NSString *path = [[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject] stringByAppendingPathComponent:@"animated.gif"];
@sdrew
sdrew / gist:1185537
Created September 1, 2011 05:48
Creating arbitrarily-colored icons from a black-with-alpha master image (iOS)
// Usage example:
// input image: http://f.cl.ly/items/3v0S3w2B3N0p3e0I082d/Image%202011.07.22%2011:29:25%20PM.png
//
// UIImage *buttonImage = [UIImage ipMaskedImageNamed:@"UIButtonBarAction.png" color:[UIColor redColor]];
// .h
@interface UIImage (IPImageUtils)
+ (UIImage *)ipMaskedImageNamed:(NSString *)name color:(UIColor *)color;
@end
@sdrew
sdrew / gist:1164016
Created August 23, 2011 00:40
Mask based CALayer hit testing
#import "CALayer_HitTestExtensions.h"
#import <objc/runtime.h>
static void *kHitMask;
@implementation CALayer (CALayer_HitTestExtensions)
- (NSUInteger)hitMask
{