Skip to content

Instantly share code, notes, and snippets.

View MMnasrabadi's full-sized avatar
🤠
i am happy

Mohammad Mohammadi Nasrabadi MMnasrabadi

🤠
i am happy
View GitHub Profile
@quangDecember
quangDecember / UserDefaults+Codable+propertyWrapper.swift
Created November 21, 2019 02:29
property wrappers for saving to UserDefaults, generics or Codable
import Foundation
@propertyWrapper
struct UserDefault<T> {
let key: String
let defaultValue: T
init(_ key: String, defaultValue: T) {
self.key = key
@quangDecember
quangDecember / wrapper+AES+CommonCrypto.swift
Created November 13, 2019 10:53
property wrappers for encryption, using builtin Apple library
import Foundation
import CommonCrypto
struct AES256 : Codable {
private var key: Data
private var iv: Data
public init(key: Data, iv: Data) throws {
guard key.count == kCCKeySizeAES256 else {
import Foundation
protocol TransformerType {
associatedtype BaseType
associatedtype TypeForCoding: Codable
static var encodeTransform: (BaseType) throws -> TypeForCoding { get }
static var decodeTransform: (TypeForCoding) throws -> BaseType { get }
}
@propertyWrapper
//
// MMTextField.swift
// MMTextField
//
// Created by Monang Champaneri
// Copyright (c) 2019 Mac Champs. All rights reserved.
//
import UIKit
@MMnasrabadi
MMnasrabadi / Download stream
Last active October 4, 2022 08:53
Download stream video format : M3U8
ffmpeg -user_agent "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_5) AppleWebKit/601.7.8 (KHTML, like Gecko) Version/9.1.3 Safari/537.86.7" -i https://branding.arvanvod.com/w4orK6pYLV/wVmowjK7OW/h_,144_200,240_400,360_800,480_1500,720_2500,k.mp4.list/index-f4-v1-a1.m3u8 -c copy Arvin.mkv
// Xcode 11b1
@propertyDelegate
struct Clamped<Value: Comparable> {
private var storage: Value
private var clamp: (Value) -> Value
init(min: Value, max: Value, initialValue: Value) {
let clampingFunction = { ($0...$0).clamped(to: min...max).lowerBound }
self.storage = clampingFunction(initialValue)
enum Demo {
case simple
case oneValue(Int)
case twoValues(String, Double)
case threeValues(one: Int, two: Float, [Int])
}
//: # Direct exposition in the enum
//: ## Sourcery Template
@AliSoftware
AliSoftware / Bindings.swift
Last active March 26, 2025 12:10
Re-implementation of @binding and @State (from SwiftUI) myself to better understand it
/*:
This is a concept re-implementation of the @Binding and @State property wrappers from SwiftUI
The only purpose of this code is to implement those wrappers myself
just to understand how they work internally and why they are needed,
⚠️ This is not supposed to be a reference implementation nor cover all
subtleties of the real Binding and State types.
The only purpose of this playground is to show how re-implementing
them myself has helped me understand the whole thing better
@AliSoftware
AliSoftware / CopyLabel.swift
Last active June 20, 2020 11:42
An UILabel subclass which allows you to show the "copy" MenuController item to copy its content to the pasteboard
import UIKit
class CopyLabel : UILabel {
// MARK: Setup
override init(frame: CGRect) {
super.init(frame: frame)
configureMenu()
}
@primaryobjects
primaryobjects / m3u8.md
Last active June 5, 2025 08:21
How to download m3u8 and ts video movie streams.

m3u8 Downloading

  1. Open Chrome Developer tools and click the Network tab.
  2. Navigate to the page with the video and get it to start playing.
  3. Filter the list of files to "m3u8".
  4. Find master.m3u8 or index.m3u8 and click on it.
  5. Save the file to disk and look inside it.
  6. If the file contains a single m3u8 master url, copy that one instead.
  7. Run the program m3u8x.
  8. Paste the same m3u8 url in both textboxes (URL and Quality URL) and click "Headers" and set the referral url and user-agent from the request as found in Chrome.