Skip to content

Instantly share code, notes, and snippets.

View fassko's full-sized avatar
👋
Hi! I'm Kristaps - Web3 and iOS Swift developer. Let's chat!

Kristaps Grinbergs fassko

👋
Hi! I'm Kristaps - Web3 and iOS Swift developer. Let's chat!
View GitHub Profile
@fassko
fassko / websocket4.swift
Created July 30, 2019 08:03
Receiving messages with Websocket iOS13
webSocketTask.receive { result in
switch result {
case .failure(let error):
print("Error in receiving message: \(error)")
case .success(let message):
switch message {
case .string(let text):
print("Received string: \(text)")
case .data(let data):
print("Received data: \(data)")
@fassko
fassko / websocket5.swift
Created July 30, 2019 08:05
Receiving messages with Websocket iOS 13
func receiveMessage() {
webSocketTask.receive { result in
switch result {
case .failure(let error):
print("Error in receiving message: \(error)")
case .success(let message):
switch message {
case .string(let text):
print("Received string: \(text)")
case .data(let data):
@fassko
fassko / websocket6.swift
Created July 30, 2019 08:06
Ping/ping with Websockets iOS13
func sendPing() {
webSocketTask.sendPing { (error) in
if let error = error {
print("Sending PING failed: \(error)")
}
DispatchQueue.main.asyncAfter(deadline: .now() + 10) {
self.sendPing()
}
}
@fassko
fassko / websocket7.swift
Created July 30, 2019 08:10
Close Websocket
webSocketTask.cancel(closeCode: .goingAway, reason: nil)
@fassko
fassko / websocket8.swift
Created July 30, 2019 08:11
Websocket connection state with iOS 13
// connection disconnected
func urlSession(URLSession, webSocketTask: URLSessionWebSocketTask,
didCloseWith: URLSessionWebSocketTask.CloseCode,
reason: Data?)
// connection established
func urlSession(URLSession, webSocketTask: URLSessionWebSocketTask, didOpenWithProtocol: String?)
@fassko
fassko / Then.swift
Created April 8, 2020 08:25
Do / with shorthand
import UIKit
public protocol Then {}
extension Then where Self: Any {
/// Makes it available to set properties with closures just after initializing and copying the value types.
///
/// let frame = CGRect().with {
/// $0.origin.x = 10
//SPDX-License-Identifier: Unlicense
pragma solidity ^0.8.0;
contract Accessibility {
uint public publicInt;
uint internal internalInt;
uint private privateInt;
uint externalInt; // for external function
//SPDX-License-Identifier: Unlicensed
pragma solidity ^0.8.0;
contract DynamicSizeArray {
uint256[] _array;
function add(uint256 _value) external {
_array.push(_value);
}
@fassko
fassko / contracts...NFTTallinn.sol
Created March 23, 2022 19:59
Created using remix-ide: Realtime Ethereum Contract Compiler and Runtime. Load this file by pasting this gists URL or ID at https://remix.ethereum.org/#version=soljson-v0.8.7+commit.e28d00a7.js&optimize=false&runs=200&gist=
//SPDX-License-Identifier: Unlicensed
pragma solidity ^0.8.0;
import "@openzeppelin/contracts/token/ERC721/ERC721.sol";
import "@openzeppelin/contracts/token/ERC721/extensions/ERC721URIStorage.sol";
import "@openzeppelin/contracts/utils/Counters.sol";
import "@openzeppelin/contracts/token/ERC721/extensions/IERC721Metadata.sol";
contract NFTTallinnTicket is ERC721URIStorage {
using Counters for Counters.Counter;
@fassko
fassko / contracts...Mappings.sol
Created April 7, 2022 17:55
Created using remix-ide: Realtime Ethereum Contract Compiler and Runtime. Load this file by pasting this gists URL or ID at https://remix.ethereum.org/#version=soljson-v0.8.7+commit.e28d00a7.js&optimize=false&runs=200&gist=
//SPDX-License-Identifier: Unlicense
pragma solidity ^0.8.0;
contract Mappings {
mapping(address => uint256) private luckyNumbers;
function getMyLuckyNumber() external view returns(uint256) {
require(luckyNumbers[msg.sender] != 0, "0 can't be lucky");
return luckyNumbers[msg.sender];