Skip to content

Instantly share code, notes, and snippets.

@brackendev
brackendev / .gitignore
Last active July 1, 2019 19:31 — forked from adamgit/.gitignore
[iOS] .gitignore
#########################
# .gitignore file for Xcode4 / OS X Source projects
#
# Version 2.0
# For latest version, see: http://stackoverflow.com/questions/49478/git-ignore-file-for-xcode-projects
#
# 2013 updates:
# - fixed the broken "save personal Schemes"
#
# NB: if you are storing "built" products, this WILL NOT WORK,
@brackendev
brackendev / DeepCleanXcodeProject.sh
Last active January 6, 2020 20:11
[Shell] Deep clean Xcode project
#!/bin/sh
# Deep clean Xcode project. Run from project root directory.
if [ -d "build" ]; then
/bin/rm -rf "build"
fi
if [ -d "$HOME/Library/Developer/Xcode/DerivedData" ]; then
/bin/rm -rf "$HOME/Library/Developer/Xcode/DerivedData/*"
fi
@brackendev
brackendev / CreateWebToken.st
Last active July 18, 2019 00:34
[Pharo] Create and validate JSON Web Tokens
"Signature validates on www.jwt.io"
| dictToSign secret headerD headerJ headerE payloadJ payloadE joined signed signedE |
dictToSign := Dictionary new at: 'test' put: 123.
secret := 'secret'.
"Don't change below"
headerD := Dictionary new at: 'alg' put: 'HS256'; at: 'typ' put: 'JWT'; yourself.
headerJ := NeoJSONWriter toString: headerD.
headerE := ZnBase64Encoder new encode: (ZnUTF8Encoder new encodeString: headerJ) asByteArray.
payloadJ := NeoJSONWriter toString: dictToSign.
payloadE := ZnBase64Encoder new encode: (ZnUTF8Encoder new encodeString: payloadJ) asByteArray.
@brackendev
brackendev / NSNotificationCenter+Token.h
Last active July 6, 2019 06:19
[Objective-C] Unregistering block-based NotificationCenter observers using "Resource acquisition is initialization" (RAII)
//
// NSNotificationCenter+Token.h
//
// Created by brackendev
// Based on Ole Begemann's article and Swift implementation <https://oleb.net/blog/2018/01/notificationcenter-removeobserver/>
//
@import Foundation;
@class NotificationToken;
@brackendev
brackendev / FSharp-Bootstrap.sh
Last active July 7, 2019 03:28
[Shell] Bootstrap an F# Visual Studio solution on UNIX (with console, library, and test projects)
#!/bin/sh
# Bootstrap an F# Visual Studio solution on UNIX (with console, library, and test projects)
########## Create solution ##########
mkdir $1
cd $1
dotnet new sln
echo •••••••••• $1 solution created ••••••••••
########## Create library project ##########
@brackendev
brackendev / RecursiveBlockExample.st
Last active July 13, 2019 16:28
[Pharo] Recursive block example
"Recursive block example"
| limit block |
limit := 10.
block := [ :count |
Transcript crShow: count asString.
(count = limit) ifFalse: [ block value: count + 1 ].
].
block value: 1.
@brackendev
brackendev / LastFridays.st
Last active July 11, 2019 04:54
[Pharo] Last Friday of each month
"https://rosettacode.org/wiki/Last_Friday_of_each_month"
| lastFriday |
lastFriday := [ :yr | | firstDay firstFriday |
firstDay := Date year: yr month: 1 day: 1.
firstFriday := firstDay addDays: (6 - firstDay dayOfWeek).
(0 to: 53)
collect: [ :each | firstFriday addDays: (each * 7) ]
thenSelect: [ :each |
(((Date daysInMonth: each monthIndex forYear: yr) - each dayOfMonth) <= 6) and: [ each year = yr ] ] ].
lastFriday value: 2019.
@brackendev
brackendev / DetectDivisionByZero.st
Last active July 17, 2019 12:09
[Pharo] Detect division by zero
"https://rosettacode.org/wiki/Detect_division_by_zero"
| zeroDivide |
zeroDivide := [ :aBlock |
[ aBlock value. false ] on: ZeroDivide do: [ true ].
].
zeroDivide value: [2/1]. "false"
zeroDivide value: [2/0]. "true"
@brackendev
brackendev / sample-rss-2.0-feed.xml
Created July 24, 2019 21:45 — forked from ToddG/sample-rss-2.0-feed.xml
sample-rss-2.0-feed
<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0">
<channel>
<title>Example Feed</title>
<description>Insert witty or insightful remark here</description>
<link>http://example.org/</link>
<lastBuildDate>Sat, 13 Dec 2003 18:30:02 GMT</lastBuildDate>
<managingEditor>johndoe@example.com (John Doe)</managingEditor>
@brackendev
brackendev / lol-clozure-ccl.lisp
Last active October 3, 2019 00:28
[Common Lisp] Land of Lisp with Clozure CL
;; Page 120
(defun dot->png (fname thunk)
(with-open-file (*standard-output*
fname
:direction :output
:if-exists :supersede)
(funcall thunk))
(ccl:run-program "/usr/local/bin/dot" (list "-Tpng" "-O" fname)))