Skip to content

Instantly share code, notes, and snippets.

@bre7
bre7 / readme.md
Created April 3, 2018 23:49
Running Swift on Windows 10
@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 / 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 / google.analytics.palette.fixer.user.js
Last active January 12, 2019 02:08
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
// ==UserScript==
// @name Google Analytics color fixer
// @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
// @version 0.4
// @author You
// @match https://analytics.google.com/analytics/web/*embed/report-home/*/
// @match https://analytics.google.com/analytics/web/*
// @grant GM_addStyle
// ==/UserScript==
$(document).ready(function() {
$.waypoints.settings.scrollThrottle = 30;
$('#main').waypoint(function(event, direction){
/* Just as we have a sticky class applied when we hit the top waypoint,
we'll have a different class applied when we bottom out */
if (direction === 'down') {
$(this).removeClass('sticky').addClass('bottomed');
}
else {
$(this).removeClass('bottomed').addClass('sticky');
$(document).ready(function() {
$.waypoints.settings.scrollThrottle = 30;
$('#main').waypoint(function(event, direction){
/* Just as we have a sticky class applied when we hit the top waypoint,
we'll have a different class applied when we bottom out */
if (direction === 'down') {
$(this).removeClass('sticky').addClass('bottomed');
}
else {
$(this).removeClass('bottomed').addClass('sticky');
@bre7
bre7 / OpacityLoopAnimation.coffee
Last active February 7, 2018 00:40
Just getting started with Framer & CoffeeScript. This a a loop animation which modifies a layer's opacity
class OpacityLoopAnimation
constructor: (options={}) ->
fadeInAnimation = new Animation({
layer: options.layer,
properties: {
opacity: 1.00
}
time: 1
curve: Bezier.easeIn
@bre7
bre7 / vimeo_thumbs.py
Last active February 4, 2018 23:23
Bulk Vimeo thumbnail downloader
## Save links in a file named "links.txt" (they are extracted so you can save HTML or w/e)
## Run the script
## πŸŽ‰πŸŽ‰πŸŽ‰
import httplib2
import json
import string
import sys
import urllib
import re
@bre7
bre7 / scanner-with-imagemagick.md
Last active November 17, 2023 23:04
Simulate photo copier / fax / scanner effect using ImageMagick

Solution 1

convert original.pdf -colorspace gray +clone -blur 0x1 +swap -compose divide -composite -linear-stretch 5%x0% -rotate 1.5 fake-scanned.pdf

Colorscan variation:

Simple benchmarking in Swift

Credit goes to NSHipster: http://nshipster.com/benchmarking/

  1. Add the following to the bridging header:
#include <stdint.h>
extern uint64_t dispatch_benchmark(size_t count, void (^block)(void));