Skip to content

Instantly share code, notes, and snippets.

@gboyegadada
gboyegadada / multiline.exs
Created March 25, 2024 15:27 — forked from squarism/multiline.exs
Multiline Anonymous Functions in Elixir
# Examples of Different Styles and Syntax
# legal / positive case / you can do these stuffs
# ---------------------------------------------------------------------------
# single line, nothing special
Enum.map(0...2, fn i -> IO.puts i end)
"""
0
1
@gboyegadada
gboyegadada / ExampleView.swift
Last active January 13, 2024 03:01
Simple GIF player for Swift. Tested on macOS but should work with iOS too (remember to switch NSImage to UIImage in the example)
//
// ExampleView.swift
//
// Created by Gboyega Dada on 13/01/2024.
//
import SwiftUI
struct ExampleView: View {
var src: URL
@gboyegadada
gboyegadada / TransferableItem.swift
Last active March 8, 2024 15:27
[Mac OS] Custom Copy / Paste with Swift UI Transferable + support for NSPasteboard (NSPasteboardWriting, NSPasteboardReading) and drag / drop
//
// TransferableItem.swift
//
// Created by Gboyega Dada on 22/11/2023.
//
// @see https://stackoverflow.com/a/57648296/1661299
// @see https://exploringswift.com/blog/creating-a-nsitemprovider-for-custom-model-class-drag-drop-api
// @see https://stackoverflow.com/a/66169874/1661299
//
@gboyegadada
gboyegadada / ImagePixelDimensions.swift
Last active November 14, 2023 13:24
[ Swift for Mac OS ] Load video meta data from URL – duration, natural size and creation date (and more) in Swift. This looks expensive so make sure you store results somewhere for re-use. Bonus: get image pixel dimensions from (local image file) URL!
// For images...
import AppKit
extension URL {
func getImageSize() -> CGSize? {
guard let src = CGImageSourceCreateWithURL(self as CFURL, nil) else {
return nil
}
@gboyegadada
gboyegadada / Decodable.swift
Last active November 5, 2023 06:41
Simple view model for extracting `og:meta` tags from a web page with Swift and WKWebView (without displaying the web view).
struct WebImageMetaData: Decodable {
let title: String?
let summary: String?
let url: URL?
let image: URL?
let mimetype: String?
let width: String?
let height: String?
private enum CodingKeys: String, CodingKey {
@gboyegadada
gboyegadada / sendCodePipelineApprovalRequestToSlack.js
Last active February 21, 2018 15:47
Send approval request from AWS CodePipeline to Slack using SNS and Lambda
// Based on: https://gist.github.com/terranware/962da63ca547f55667f6
var https = require('https');
var util = require('util');
exports.handler = function(event, context) {
console.log(JSON.stringify(event, null, 2));
console.log('From SNS:', event.Records[0].Sns.Message);
var postData = {