This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
import unittest | |
from sha3 import keccak_256 | |
def checksum_encoded(addr): | |
checksumed = '' | |
hashed = keccak_256(addr.encode('utf-8')).digest().hex()[:40] | |
for idx, character in enumerate(addr): | |
if character in "0123456789": # Decimal digits should be passed as they are | |
checksumed += character |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import UIKit | |
struct PackingList { | |
let heavyCoat: Int | |
let rainJacket: Int | |
let pullover: Int | |
let activewearCoat: Int | |
let thermalUnderwear: Int | |
let leggins: Int | |
let darkJean: Int |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
from random import SystemRandom | |
import ecdsa | |
p = 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFFC2F | |
order = 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEBAAEDCE6AF48A03BBFD25E8CD0364141 | |
# Remember the equiation we are using is `y^2 % p == x^3 + 7 | |
a = 0x0000000000000000000000000000000000000000000000000000000000000000 | |
b = 0x0000000000000000000000000000000000000000000000000000000000000007 | |
# This is the generator point defined in the standard |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//: Playground - noun: a place where people can play | |
import Cocoa | |
class Node<T: Comparable> { | |
var next: Node<T>? | |
let value: T | |
init(value: T) { | |
self.value = value |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//: Playground - noun: a place where people can play | |
import Cocoa | |
struct State { | |
var state: [Int] | |
init(state: [Int]) { | |
self.state = state | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import bisect | |
class NFA(object): | |
EPSILON = object() | |
ANY = object() | |
def __init__(self, start_state): | |
self.transitions = {} | |
self.final_states = set() | |
self._start_state = start_state |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import XCTest | |
@testable import WeatherApp | |
extension XCTestCase { // JSON support | |
func jsonData(payload: Any) throws -> Data { | |
let options: JSONSerialization.WritingOptions = [.prettyPrinted, .sortedKeys] | |
let data = try JSONSerialization.data(withJSONObject: payload, options: options) | |
return data | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//: Playground - noun: a place where people can play | |
import UIKit | |
extension Character { | |
var asciiValue: Int { | |
get { | |
let s = String(self).unicodeScalars | |
return Int(s[s.startIndex].value) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//: Playground - noun: a place where people can play | |
import UIKit | |
// General Case for an Array | |
extension Array where Element:Hashable { | |
mutating func deleteElements(_ elements:[Element]) -> ArraySlice<Element> { | |
var toDelete: [Element: Bool] = [:] | |
for e in elements { | |
toDelete[e] = true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//: Playground - noun: a place where people can play | |
import UIKit | |
extension String { | |
private func reverseChars(chars: inout [String.Element], range: Range<Int>) { | |
guard chars.count > 1 else { | |
return | |
} |
NewerOlder