Skip to content

Instantly share code, notes, and snippets.

View lotusirous's full-sized avatar
💭
for { Learn() }

Kha Nguyen lotusirous

💭
for { Learn() }
View GitHub Profile
@lotusirous
lotusirous / sse.go
Created February 25, 2020 13:19
A sample server sent event with golang
package main
import (
"context"
"fmt"
"io"
"net/http"
"os"
"os/signal"
"syscall"
@lotusirous
lotusirous / app.py
Created January 26, 2019 12:38
Example of flask blueprint and register logging to root logger
import logging
from flask import Flask
from werkzeug.utils import find_modules, import_string
def configure_logging():
# register root logging
logging.basicConfig(level=logging.DEBUG)
logging.getLogger('werkzeug').setLevel(logging.INFO)
@lotusirous
lotusirous / dropdown.swift
Created December 1, 2022 07:23
A elegant solution dropdown menu for SwiftUI
//
// ContentView.swift
// WeirdSheet
//
// Created by lotusirous on 28/11/2022.
//
import SwiftUI
protocol Nameable {
type stack []rune
func (s *stack) push(n rune) {
*s = append(*s, n)
}
func (s *stack) pop() rune {
if s.empty() {
panic("stack is empty")
@lotusirous
lotusirous / auto_renew_token.swift
Last active October 22, 2022 10:56
An example of auto renew token and fetch the resource
import Combine
import Foundation
enum NetworkError: Error {
case unauthorized
case badServerResponse
case wrongType
case unknown
}
@lotusirous
lotusirous / onetime_token_server.go
Created October 22, 2022 03:37
A mock one time token
package main
import (
"fmt"
"log"
"math/rand"
"net/http"
"time"
)
@lotusirous
lotusirous / record_audio.swift
Created October 20, 2022 04:50
Live record and stream the buffer with combine Passthrough
//
// StreamRecorder.swift
// pesos
//
// Created by Gru-2019015 on 2022/08/26.
//
import AVFoundation
import Combine
import Foundation
def split_by_n(seq, n):
"""Split a sequence by n elements"""
while seq:
yield seq[:n]
seq = seq[n:]
@lotusirous
lotusirous / xss_jquery.html
Last active August 23, 2022 16:53
Example of XSS vulnerability on Jquery 1.4.2
<html>
<head>
<meta charset="utf-8">
<title>XSS Reflected - Jquery 1.4.2 </title>
<script src="http://www.tcs.com.vn/mysite/javascript/jquery-1.4.2.min.js"></script>
<script>
$(function() {
$('#users').each(function() {
var select = $(this);
var option = select.children('option').first();
@lotusirous
lotusirous / combine_http.swift
Created March 8, 2022 02:00
A good way to handle HTTP in swift combine
let url = URL(string: "https://postman-echo.com/time/valid?timestamp=2016-10-10")!
struct PostmanResponse: Decodable {
let valid: Bool
}
enum ApiError: Error {
case invalidServerResponse
}