Skip to content

Instantly share code, notes, and snippets.

View content.swift
struct PostContent: Codable {
struct Paragraph: Codable {
let id: String
let text: String
}
struct Section: Codable {
let id: String
let startIndex: Int
}
var paragraphs: [Paragraph]
@kmdarshan
kmdarshan / sample.json
Created September 23, 2019 07:05
sample json
View sample.json
{
"paragraphs": [{
"id": "p0",
"text": "aaa"
},
{
"id": "p1",
"text": "bbb"
},
{
@kmdarshan
kmdarshan / .cpp
Created August 28, 2019 14:05
stopping debugger
View .cpp
#ifdef _MSC_VER
// windows OS
# define BREAK_HERE() __debugbreak()
#elif defined(ARCH_X64) || defined(ARCH_X86)
// linux or iOS based systems
# define BREAK_HERE() __asm__("int $3")
#else
# define BREAK_HERE() raise(SIGTRAP)
#endif
@kmdarshan
kmdarshan / factory.swift
Created August 28, 2019 14:03
Factory method implementation in Swift
View factory.swift
//: A UIKit based Playground for presenting user interface
import UIKit
import PlaygroundSupport
enum Maps : Int {
case google = 1
case apple
}
@kmdarshan
kmdarshan / attributedText.swift
Created August 21, 2019 20:10
Using attributed text in Swift
View attributedText.swift
import UIKit
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
let html = """
<html>
<body>
<p style="color: blue;
font-size: 20px;
">
@kmdarshan
kmdarshan / gist:2c015c0d0b7746df4a10a15aeb18acf3
Created August 21, 2019 19:58
Detecting interlaced videos using ffmpeg
View gist:2c015c0d0b7746df4a10a15aeb18acf3
/Users/darshan/Downloads/ffmpeg -filter:v idet -frames:v 100 -an -f rawvideo -y /dev/null -i /Users/darshan/Dropbox/Public/1080i/interlaced/Mug\ Drop_Interlaced_4ss.mp4
video:303750kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.000000%
[Parsed_idet_0 @ 0x7facaf200000] Repeated Fields: Neither: 63 Top: 20 Bottom: 18
[Parsed_idet_0 @ 0x7facaf200000] Single frame detection: TFF: 81 BFF: 0 Progressive: 20 Undetermined: 0
[Parsed_idet_0 @ 0x7facaf200000] Multi frame detection: TFF: 101 BFF: 0 Progressive: 0 Undetermined: 0
@kmdarshan
kmdarshan / fizzbuzz.swift
Created May 22, 2019 06:18
Fizzbuzz problem in swift
View fizzbuzz.swift
Write a program that outputs the string representation of numbers from 1 to n.
But for multiples of three it should output “Fizz” instead of the number and for the multiples of five output “Buzz”. For numbers which are multiples of both three and five output “FizzBuzz”.
Example:
n = 15,
Return:
[
@kmdarshan
kmdarshan / minRotation.swift
Created May 22, 2019 03:00
Find Minimum in Rotated Sorted Array II
View minRotation.swift
func findMin(_ nums: [Int]) -> Int {
let firstElement = nums[0]
let lastElement = nums[nums.count-1]
if(firstElement < lastElement)
{
// go from the first element
var minElement = firstElement
for item in nums
{
if !(item > firstElement) && (item < lastElement)
View gist:f9900e3b05f46096fc674d062f2441b7
import UIKit
class Solution {
func flipAndInvertImage(_ A: [[Int]]) -> [[Int]]
{
if(A.count > 0)
{
var finalArray = [[Int]]()
for item in A {
View gist:b56c06d8a432a3639911f9adc609aed4
// First thing is you need a AVAsset.
// Once you have an asset, you need to determine the type of preset you need to use.
// You can consider a preset as a set of properties, which is provided to the exporter.
// I do this for helping me with my export.
-(NSString*)determineCompatibleExportPresetForAsset:(AVAsset*)asset
{
NSArray<NSString*>* presetsRankedByPriority = @[AVAssetExportPresetHighestQuality, AVAssetExportPresetMediumQuality, AVAssetExportPresetLowQuality];
NSArray* compatiblePresets = [AVAssetExportSession exportPresetsCompatibleWithAsset:asset];
for (NSString* preset in presetsRankedByPriority)