Skip to content

Instantly share code, notes, and snippets.

Avatar
😈

Nico Prananta nicnocquee

😈
View GitHub Profile
View advanced-swiftui-animations.swift
//------------------------------------------------------------------------
// The SwiftUI Lab: Advanced SwiftUI Animations
// https://swiftui-lab.com/swiftui-animations-part1 (Animating Paths)
// https://swiftui-lab.com/swiftui-animations-part2 (GeometryEffect)
// https://swiftui-lab.com/swiftui-animations-part3 (AnimatableModifier)
//------------------------------------------------------------------------
import SwiftUI
struct ContentView: View {
@nicnocquee
nicnocquee / node-tcp.js
Created April 12, 2022 03:09
simple tcp server with node.js
View node-tcp.js
const Net = require("net");
// The port on which the server is listening.
const port = 8080;
// Use net.createServer() in your code. This is just for illustration purpose.
// Create a new TCP server.
const server = new Net.Server();
// The server listens to a socket for a client to make a connection request.
// Think of a socket as an end point.
server.listen(port, function () {
View swiftid-usersme.swift
struct MeResponseData: Decodable {
let id: Int
let username: String
let email: String
}
func me(authToken: String? = nil) async throws -> MeResponseData {
let meData: MeResponseData = try await URLSession.shared.get(pathname: "/users/me", authToken: authToken)
return meData
}
View swiftid-login.swift
struct LoginRequestData: Encodable {
let identifier: String
let password: String
}
struct LoginResponseData: Decodable {
let jwt: String
}
func login(_ loginRequest: LoginRequestData) async throws -> String {
// URLSession.shared.post is an extension which you can find here https://gist.github.com/nicnocquee/f0a0dbe345f0a18a378d9022c7d11e9c#gistcomment-3964831
let loginData: LoginResponseData = try await URLSession.shared.post(pathname: "/auth/local", data: loginRequest)
View swiftid-register.swift
struct RegisterRequestData: Encodable {
let username: String
let email: String
let password: String
}
struct LoginResponseData: Decodable {
let jwt: String
}
@nicnocquee
nicnocquee / EnumListView.swift
Created March 17, 2021 13:10
Swift Enumerations to SwiftUI list view
View EnumListView.swift
struct EnumListView<Enum: RawRepresentable &
CaseIterable &
CustomStringConvertible> : View where
Enum.RawValue: Hashable,
Enum.AllCases: RandomAccessCollection {
var title: String = ""
@Binding var selectedItem: Enum?
var body: some View {
@nicnocquee
nicnocquee / pokemon-fetch-combine.swift
Created February 5, 2021 17:41
sample of fetching list of pokemon using swift combine
View pokemon-fetch-combine.swift
import UIKit
import Combine
struct PokemonResponse: Codable{
let results: [Pokemon]
}
struct Pokemon: Codable{
let name: String
@nicnocquee
nicnocquee / next.config.js
Created May 5, 2020 15:41
Small function to expose environment variables to nextjs app
View next.config.js
require('dotenv').config()
const getEnvWithPrefixes = (prefixes = ['REACT_APP_', 'FIREBASE_']) => {
return Object.keys(process.env).reduce((prev, curr) => {
if (prefixes.some(p => curr.startsWith(p))) {
return {
...prev,
[curr]: process.env[curr],
}
}
@nicnocquee
nicnocquee / uicollectionview-playground.playyground
Created October 19, 2018 06:37
Testing UICollectionView in Swift Playground iPad
View uicollectionview-playground.playyground
import UIKit
import PlaygroundSupport
let cellSize = CGSize(width: 100, height: 100)
class Cell: UICollectionViewCell {
var imageView: UIImageView?
var identifier: String?
required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
@nicnocquee
nicnocquee / my_alias.sh
Last active April 24, 2017 06:51
my shell alias
View my_alias.sh
# Color LS
colorflag="-G"
alias ls="command ls ${colorflag}"
alias l="ls -lF ${colorflag}" # all files, in long format
alias la="ls -laF ${colorflag}" # all files inc dotfiles, in long format
alias lsd='ls -lF ${colorflag} | grep "^d"' # only directories
alias lsa="command ls -la | lolcat"
# Quicker navigation
alias ..="cd .."