Skip to content

Instantly share code, notes, and snippets.

@bre7
bre7 / dictionary.json.extensions.swift
Created March 2, 2018 22:04
Swift Dictionary + Encodable extensions
/// Source: https://stackoverflow.com/questions/45209743/how-can-i-use-swift-s-codable-to-encode-into-a-dictionary
extension Encodable {
/// Converts an Encodable entity to it's Dictionary representation (throwable)
func asDictionary() throws -> [String: Any] {
let data = try JSONEncoder().encode(self)
guard let dictionary = try JSONSerialization.jsonObject(with: data, options: .allowFragments) as? [String: Any] else {
throw NSError()
}
return dictionary
@bre7
bre7 / LogMiddleware.swift
Created April 3, 2018 15:39
Vapor 3 Logging Middleware example
import Foundation
import Vapor
/// Logs all requests that pass through it.
final class LogMiddleware: Middleware, Service {
let log: Logger
/// Creates a new `LogMiddleware`.
init(log: Logger) { self.log = log }
@bre7
bre7 / readme.md
Created April 3, 2018 23:49
Running Swift on Windows 10
@bre7
bre7 / FileMiddlewareWithCache.swift
Created April 6, 2018 03:12
Vapor 3 Middleware to serve files from the public folder and respect Cache-Control headers
import Vapor
/// Services files from the public folder.
public final class FileMiddlewareWithCache: Middleware, Service {
/// The public directory.
/// note: does _not_ end with a slash
let publicDirectory: String
public var webTypes = [MediaType]()
@bre7
bre7 / upload-github-release-asset.sh
Created April 11, 2018 21:18 — forked from stefanbuck/upload-github-release-asset.sh
Script to upload a release asset using the GitHub API v3.
#!/usr/bin/env bash
#
# Author: Stefan Buck
# License: MIT
# https://gist.github.com/stefanbuck/ce788fee19ab6eb0b4447a85fc99f447
#
#
# This script accepts the following parameters:
#
# * owner
@bre7
bre7 / prefix.js
Created June 23, 2018 03:45
Javascript vendor prefixer
// Source: Another gist, will update if I can get the link
// Replace # with the first letter of the function
["#","webkit#","moz#","ms#","o#"].reduce(function(p, v) { return window[v + p] || p; }, "#FUNCTION_NAME");
// E.g. requestAnimationFrame (vendor prefix not needed anymore)
["r","webkitR","mozR","msR","oR"].reduce(function(p, v) { return window[v + p] || p; }, "equestAnimationFrame");
@bre7
bre7 / compress_pdf.md
Created July 5, 2018 19:35 — forked from ahmed-musallam/compress_pdf.md
How to compress PDF with ghostscript

How to compress PDF using ghostscript

As a developer, it bothers me when someone sends me a large pdf file compared to the number of pages. Recently, I recieved a 12MB scanned document for just one letter-sized page... so I got to googlin, like I usually do, and found ghostscript!

to learn more abot ghostscript (gs): https://www.ghostscript.com/

What we are interested in, is the gs command line tool, which provides many options for manipulating PDF, but we are interested in compressign those large PDF's into small yet legible documents.

credit goes to this answer on askubuntu forum: https://askubuntu.com/questions/3382/reduce-filesize-of-a-scanned-pdf/3387#3387?newreg=bceddef8bc334e5b88bbfd17a6e7c4f9

@bre7
bre7 / TwitterListsInMenubar.user.js
Created October 20, 2018 02:42
Add Twitter List icon to tabbar (next to Profile icon)
// ==UserScript==
// @name Lists in tabbar
// @version 1.0
// @description Show Lists icon next to the user avatar
// @author You
// @match https://twitter.com/*
// @grant none
// ==/UserScript==
function ready(fn) {
@bre7
bre7 / README.md
Created November 8, 2018 01:54 — forked from hubgit/README.md
Remove metadata from a PDF file, using exiftool and qpdf. Note that embedded objects may still contain metadata.

Anonymising PDFs

PDF metadata

Metadata in PDF files can be stored in at least two places:

  • the Info Dictionary, a limited set of key/value pairs
  • XMP packets, which contain RDF statements expressed as XML

PDF files

@bre7
bre7 / google.analytics.color.fixer.user.css
Last active February 11, 2019 14:45
Google Analytics Color Fixer
/* ==UserStyle==
@name Google Analytics color fixer
@namespace github.com/openstyles/stylus
@version 1.0.0
@description Swaps the default blue-based palette with a proper one. Thanks to https://learnui.design/tools/data-color-picker.html for the idea & color selection
@author You
@updateURL https://gist.githubusercontent.com/bre7/a0fb9886e8b4251cc1f69274fd0af96f/raw/google.analytics.color.fixer.user.css
@preprocessor stylus
==/UserStyle== */