Skip to content

Instantly share code, notes, and snippets.

View fpg1503's full-sized avatar
🐥

Francesco fpg1503

🐥
View GitHub Profile
@fpg1503
fpg1503 / ColorContext+UITraitCollection.swift
Created June 7, 2019 22:12
Dynamic Color Palettes that resolve immediately on older versions
extension ColorContext {
@available(iOS 13.0, *)
init(_ traitCollection: UITraitCollection,
defaultMode: Mode = .light,
defaultElevation: Elevation = .base,
defaultAccessibilityContrast: AccessibilityContrast = .normal) {
mode = {
switch traitCollection.userInterfaceStyle {
case .light: return .light
case .dark: return .dark
@fpg1503
fpg1503 / flatBoletim.js
Created July 28, 2018 10:30
Making an arbitrary JS Object nicer to work with
// Takes as input something like https://scontent-mad1-1.xx.fbcdn.net/v/t1.0-9/37899360_1857828550996984_1194250836729921536_o.jpg?_nc_cat=0&oh=04a7e8328932298e0f6eeec0764cd5b0&oe=5BD2D7EB
function flatBoletim(boletim) {
const innerAssign = (target, ...sources) => {
sources.forEach(source => {
Object.keys(source).forEach(key => target[key] = Object.assign(target[key] || {}, source[key]))
})
return target
}
const semesters = boletim.reduce((obj, current) => Object.assign({}, obj, {...current}), {})
const entries = Object.entries(semesters)
@fpg1503
fpg1503 / js.js
Last active August 29, 2018 02:23
jsStrings.js
// The goal is to create all letters using only !, [], {}, (), + and typeof
// Suggestions are welcome.
// Let's decrease the sizes!
// Big thanks to https://github.com/RedSparr0w, https://github.com/aemkei/jsfuck, and https://github.com/alcuadrado/hieroglyphy
const js = {
A: '(+![]+[][([][(![]+[])[+[]]+([![]]+[][[]])[+!+[]+[+[]]]+(![]+[])[!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+!+[]]]+[])[!+[]+!+[]+!+[]]+(!![]+[][(![]+[])[+[]]+([![]]+[][[]])[+!+[]+[+[]]]+(![]+[])[!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+!+[]]])[+!+[]+[+[]]]+([][[]]+[])[+!+[]]+(![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[])[+!+[]]+([][[]]+[])[+[]]+([][(![]+[])[+[]]+([![]]+[][[]])[+!+[]+[+[]]]+(![]+[])[!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+!+[]]]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[][(![]+[])[+[]]+([![]]+[][[]])[+!+[]+[+[]]]+(![]+[])[!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+!+[]]])[+!+[]+[+[]]]+(!![]+[])[+!+[]]])[+!+[]+[+[]]]',
B: '(+![]+(![
@fpg1503
fpg1503 / safeProxy.js
Last active April 18, 2018 18:27
Safe Proxy
Object.prototype.toSafeProxy = function() {
const getter = (target, name, receiver) => {
const value = target[name]
if (value == null) {
return nullProxy(value)
} else if (typeof value === 'object') {
return value.toSafeProxy()
} else if (typeof value === 'function') {
return value
@fpg1503
fpg1503 / remove_black_background.py
Created February 26, 2018 14:46
Remove image background and leave only white pixels
from PIL import Image
image = Image.open('img.png').convert("RGBA")
pixels = image.getdata()
new_pixels = list(map(lambda item: (255, 255, 255, 0) if item[0] < 250 and item[1] < 250 and item[2] < 250 else item, pixels))
image.putdata(new_pixels)
image.save("img2.png", "PNG")
enum Year {
noPadding = "y",
twoDigits = "yy",
fourDigits = "yyyy"
}
enum Quarter {
number = "Q",
zeroPaddedNumber = "QQ",
qAndNumber = "QQQ",
@fpg1503
fpg1503 / Immutable.swift
Created January 25, 2018 06:55
(a == 1 && a == 2 && a ==3).swift
//: Playground - noun: a place where people can play
struct EqualsMultiple<T: Equatable> {
let values: [T]
}
extension EqualsMultiple: ExpressibleByArrayLiteral {
typealias ArrayLiteralElement = T
init(arrayLiteral elements: T...) {
@fpg1503
fpg1503 / Promise.swift
Last active October 17, 2017 01:11
[WIP] Promises from scratch
import Foundation
import PlaygroundSupport
enum PromiseState<T> {
case pending
case fulfilled(T)
case rejected(Error)
var isPending: Bool {
switch self {
import requests
from bs4 import BeautifulSoup
all_symbols = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890"
url = "http://protext.herokuapp.com/?text=" + all_symbols
request = requests.get(url)
parsed_html = BeautifulSoup(request.text, "html.parser")
all_keys = list(all_symbols)
all_values = list(parsed_html.find('h1').text)
@fpg1503
fpg1503 / CartographyBoilerplate.swift
Last active April 19, 2017 11:54
Cartography Boilerplate
import Cartography
final class <#Name#>View: UIView {
init() {
super.init(frame: .zero)
self.buildViews()
}
required init?(coder aDecoder: NSCoder) {