Skip to content

Instantly share code, notes, and snippets.

View Sajjon's full-sized avatar
💭
FOSS|Rust&Swift|Principal Cryptography & Middleware Engineer@RDX Works/Radix DLT

Alexander Cyon Sajjon

💭
FOSS|Rust&Swift|Principal Cryptography & Middleware Engineer@RDX Works/Radix DLT
View GitHub Profile
[
{
"lang": "en",
"viewStrings" : [
{
"viewKey" : "LoginView",
"strings" : {
"Title" : "Login",
"SignUpButtonTitle" : "Sign up"
}
@Sajjon
Sajjon / DeferExposingReturnValue.swift
Created May 25, 2016 08:51
Would be nice if Defer could expose return value
// We don't know the return value of this function! Makes it hard to debug!
func fetchUserByFirstName(firstName: String, andLastName lastName: String, fromContext context: NSManagedObjectContext) -> User? {
defer {
// Not possible, would be nice! Return value would be an implicitly declared variable
// exaclty like the variables 'newValue' and 'oldValue' in property observers!
print("return value: \(returnValue)")
}
guard !firstName.isEmpty else { print("firstName can't be empty"); return nil }
guard !lastName.isEmpty else { print("lastName can't be empty"); return nil }
@Sajjon
Sajjon / HightlightedForceUnwrap.swift
Created May 8, 2017 12:40
Using emoji char ⁉️ for highlighting usage of force unwrap of optionals
postfix operator ⁉️
postfix func ⁉️ <Value>(optional: Optional<Value>) -> Value {
return optional! as Value
}
//USAGE
let maybeString: String? = "Foobar"
let maybeString2: String? = nil
print(maybeString⁉️) //prints "Foobar"
@Sajjon
Sajjon / hack.sh
Created May 18, 2017 12:25 — forked from erikh/hack.sh
OSX For Hackers
#!/usr/bin/env sh
##
# This is script with usefull tips taken from:
# https://github.com/mathiasbynens/dotfiles/blob/master/.osx
#
# install it:
# curl -sL https://raw.github.com/gist/2108403/hack.sh | sh
#
@Sajjon
Sajjon / RxOptional+OptionalType+EmptyToNil.swift
Last active May 29, 2018 11:16
RxOptional extension mapEmptyToOptional
import RxOptional
public protocol OptionalType {
associatedtype OptionalElement
var element: OptionalElement? { get }
func asOptional() -> OptionalElement?
func asNil() -> OptionalElement?
}
public extension OptionalType {
@Sajjon
Sajjon / curve.md
Created August 4, 2018 10:04 — forked from merryhime/curve.md

Merry's very quick guide to elliptic curve crypto

An elliptic curve is made up of the following:

  1. A field, F_p.
  • What this means is all arithmetic on scalars is modulo p.
  • Modern ECC have p as some large prime.
  • For curve25519, p = 2^255 - 19, a prime.
  1. An equation and it's parameters:
@Sajjon
Sajjon / montgomery_ladder.py
Created August 4, 2018 11:17 — forked from stribika/montgomery_ladder.py
Basic Montgomery ladder implementation. In the test it works with just numbers, but you can plug in any operation.
#!/usr/bin/python3 -O
from math import floor, log
def montgomery_ladder(x, n, op, select):
k = floor(log(n, 2)) + 1
x1 = x
x2 = op(x, x)
for i in range(k - 2, -1, -1):
bit = 1 if n & (1 << i) else 0
@Sajjon
Sajjon / Montgomery.py
Created August 4, 2018 13:46 — forked from natmchugh/Montgomery.py
Montgomery Ladder
import random
class Montgomery:
# B*v^2 = u^3 + A*u^2 + u
def __init__(self, A, B, p):
self.A = A
self.B = B
self.p = p
@Sajjon
Sajjon / operatorCharacters.swift
Created September 1, 2018 08:24 — forked from natecook1000/operatorCharacters.swift
Allowed characters for Swift operators
import Foundation
extension UnicodeScalar : ForwardIndexType {
public func successor() -> UnicodeScalar {
return UnicodeScalar(value + 1)
}
}
var operatorHeads: [UnicodeScalar] = Array("=-+!*%<>&|^~?".unicodeScalars)
operatorHeads += Array("\u{00A1}" ... "\u{00A7}")
/// A dictionary wrapper that uses a `CaseIterable` type as its key.
/// This differs from a dictionary in two ways:
///
/// - Key-value pairs are accessed in a fixed order, which is the same
/// as the `Key`'s `allCases` property.
/// - Every possible key must have a value given, so using the key-based
/// subscript returns a non-optional value.
struct CaseMap<Key: CaseIterable & Hashable, Value> : Collection {
typealias Index = Key.AllCases.Index