Skip to content

Instantly share code, notes, and snippets.

@jlyonsmith
jlyonsmith / server-git.conf
Created April 13, 2018 23:13 — forked from massar/server-git.conf
Example nginx + git HTTP Smart mode (git-http-backend) + HTTP Authentication + HTTPS redirect
# Example nginx + git HTTP Smart mode (git-http-backend) + HTTP Authentication + HTTPS redirect
# jeroen@massar.ch - http://jeroen.massar.ch
server {
listen 192.0.1.1:80;
listen [2001:db8::1]:80;
# Redirect all non-HTTPS traffic to the HTTPS variant
return 301 https://$host$request_uri;
}
@jlyonsmith
jlyonsmith / unregisterServiceWorkers.js
Created March 21, 2018 14:59 — forked from mrienstra/unregisterServiceWorkers.js
Unregister service workers, verbose
navigator.serviceWorker.getRegistrations().then(function (registrations) {
if (!registrations.length) {
console.log('No serviceWorker registrations found.')
return
}
for(let registration of registrations) {
registration.unregister().then(function (boolean) {
console.log(
(boolean ? 'Successfully unregistered' : 'Failed to unregister'), 'ServiceWorkerRegistration\n' +
(registration.installing ? ' .installing.scriptURL = ' + registration.installing.scriptURL + '\n' : '') +
t = 236 # seconds
Time.at(t).utc.strftime("%H:%M:%S")
=> "00:03:56"
# Reference
# http://stackoverflow.com/questions/3963930/ruby-rails-how-to-convert-seconds-to-time
@jlyonsmith
jlyonsmith / create-icons
Last active December 8, 2016 21:13 — forked from richellis/Iconizer.sh
Ruby script to create iOS application icon sets from PDF files. Requires ImageMagick and GhostScript.
#!/usr/bin/env ruby
# Requires ImageMagick: http://www.imagemagick.org/
# Requires GhostScript: http://www.ghostscript.com/
require 'fileutils'
if ARGV.count < 2 then
puts "Usage: #{File.basename(__FILE__)} <pdf-file> [<pdf-file> ...] <project-folder>"
exit 1
end
@jlyonsmith
jlyonsmith / UIAlertController.swift
Last active November 27, 2016 19:09 — forked from pietrorea/UIAlertController.swift
UIAlertController example
let alert = UIAlertController(title: "Title", message: "Message", preferredStyle: .alert)
alert.addAction(UIAlertAction(title: "Save", style: .default, handler: { (action: UIAlertAction!) in
debugPrint("Saved")
}))
alert.addAction(UIAlertAction(title: "Cancel", style: .default, handler: { (action: UIAlertAction!) in
debugPrint("Cancel")
}))
present(alert, animated: true, completion: nil)
@jlyonsmith
jlyonsmith / add-user.sh
Last active September 21, 2016 21:34
OpenSSL Client Side Certificate Scripts
#!/bin/bash
USERNAME=$1
EMAIL=$2
if [[ "$USERNAME" == "" || "$EMAIL" == "" ]]; then
echo 'Usage: create-user USERNAME EMAIL'
exit 1
fi
#!/bin/bash
# Convert a .p12 format file to a .pem format
openssl pkcs12 -in $1 -out $2 -nodes
#!/bin/bash
# Print the SSH MD5 fingerprint (works on OSX El Capitan which defaults to a SHA256 fingerprint)
ssh-keygen -E md5 -lf ~/.ssh/id_rsa
@jlyonsmith
jlyonsmith / delete-github-merged.sh
Last active April 21, 2016 22:24 — forked from schacon/gist:942899
delete all remote branches that have already been merged into master
git branch -r --merged | grep origin | grep -v '>' | grep -v master | xargs -L1 | ruby -e 'ARGF.each { |line| a = line.match(/(?:[^\/]*)\/(.*)/).captures; puts a }' | xargs git push origin --delete
public func Log<T>(item: T, fileName: String = __FILE__, line: Int = __LINE__, funcName:String = __FUNCTION__) {
let dateFormatter = NSDateFormatter()
dateFormatter.dateFormat = "MM/dd/yyyy HH:mm:ss:SSS"
let process = NSProcessInfo.processInfo()
let threadId = "?"
var shortFileName = (NSURL(string: fileName)?.lastPathComponent?.componentsSeparatedByString(".").first)
if shortFileName == nil {
shortFileName = "unknown"
}