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 / 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));
@bre7
bre7 / wwdc-chrome.user.js
Last active June 4, 2018 21:06
WWDC unblocker for Chrome
// ==UserScript==
// @name WWDC unblocker for Chrome
// @description Allows volume control with mouse wheel // Pplay/pause with space bar // Disables auto play // Sets default volume to 20% // Double click to enter/exit fullscreen mode
// @version 1.0.2
// @author You
// @match https://developer.apple.com/videos/play/*
// @match https://developer.apple.com/wwdc/live/*
// @grant none
// @updateURL https://gist.githubusercontent.com/bre7/e615d385e72444e1e9e9a6ded2d875b2/raw
// ==/UserScript==
@bre7
bre7 / Direct_Links_in_Google_Search.user.js
Created May 4, 2017 21:04 — forked from astanin/Direct_Links_in_Google_Search.user.js
Remove indirections from Google search results on all TLDs (GreaseMonkey script)