Skip to content

Instantly share code, notes, and snippets.

@bleeckerj
bleeckerj / markdown-to-email
Created January 29, 2024 17:18 — forked from rtulke/markdown-to-email
markdown-to-email A simple script to send beautifully formatted emails that you write in Markdown. The email will have an HTML payload and a plain-text alternative, so you'll make everyone happy, including yourself.
#!/usr/bin/env python
'''
Send an multipart email with HTML and plain text alternatives. The message
should be constructed as a plain-text file of the following format:
From: Your Name <your@email.com>
To: Recipient One <recipient@to.com>
Subject: Your subject line
---
@bleeckerj
bleeckerj / Github Webhook Tutorial.md
Created May 3, 2022 20:12 — forked from jagrosh/Github Webhook Tutorial.md
Simple Github -> Discord webhook

Step 1 - Make a Discord Webhook

  1. Find the Discord channel in which you would like to send commits and other updates

  2. In the settings for that channel, find the Webhooks option and create a new webhook. Note: Do NOT give this URL out to the public. Anyone or service can post messages to this channel, without even needing to be in the server. Keep it safe! WebhookDiscord

Step 2 - Set up the webhook on Github

  1. Navigate to your repository on Github, and open the Settings Settings

Do not use forEach with async-await

TLDR: Use for...of instead of forEach in asynchronous code.

The problem

Array.prototype.forEach is not designed for asynchronous code. (It was not suitable for promises, and it is not suitable for async-await.)

For example, the following forEach loop might not do what it appears to do:

@bleeckerj
bleeckerj / Shell.swift
Created July 16, 2018 21:59 — forked from andreacipriani/Bash.swift
Execute bash commands from Swift 3
import Foundation
final class Shell
{
func outputOf(commandName: String, arguments: [String] = []) -> String? {
return bash(commandName: commandName, arguments:arguments)
}
// MARK: private
@bleeckerj
bleeckerj / Fonts.swift
Created May 19, 2018 19:47 — forked from khanlou/Fonts.swift
Print all fonts in Swift 3
UIFont.familyNames.forEach({ familyName in
let fontNames = UIFont.fontNames(forFamilyName: familyName)
print(familyName, fontNames)
})
@bleeckerj
bleeckerj / splitBy.swift
Last active March 3, 2018 14:17 — forked from ericdke/splitBy.swift
Swift: split array by chunks of given size
let arr = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]
extension Array {
func chunks(_ chunkSize: Int) -> [[Element]] {
return stride(from: 0, to: self.count, by: chunkSize).map {
Array(self[$0..<Swift.min($0 + chunkSize, self.count)])
}
}
}
@bleeckerj
bleeckerj / userAvatar.js
Created February 6, 2018 07:42 — forked from SylarRuby/userAvatar.js
NodeJs AWS S3 Upload
/**
* This gist was inspired from https://gist.github.com/homam/8646090 which I wanted to work when uploading an image from
* a base64 string.
* This code is used in my startup, Zired.
* Web: http://zired.io
*/
// You can either "yarn add aws-sdk" or "npm i aws-sdk"
const AWS = require('aws-sdk')
@bleeckerj
bleeckerj / UIImageFixedOrientationExtension.swift
Created January 11, 2018 20:46 — forked from schickling/UIImageFixedOrientationExtension.swift
Extension to fix orientation of an UIImage (Sets orientation to portrait)
extension UIImage {
func fixedOrientation() -> UIImage {
if imageOrientation == UIImageOrientation.Up {
return self
}
var transform: CGAffineTransform = CGAffineTransformIdentity
@bleeckerj
bleeckerj / crc32.swift
Created December 16, 2017 16:24 — forked from JALsnipe/crc32.swift
crc32 implemented in Swift (Swift 3)
//
// crc32.swift
// SuperSFV
//
// Created by C.W. Betts on 8/23/15.
//
//
/* crc32.swift -- compute the CRC-32 of a data stream
Copyright (C) 1995-1998 Mark Adler
Copyright (C) 2015 C.W. "Madd the Sane" Betts