Skip to content

Instantly share code, notes, and snippets.

@staltz
staltz / introrx.md
Last active May 14, 2024 03:08
The introduction to Reactive Programming you've been missing
@nehayward
nehayward / ScanViewController.swift
Created November 18, 2019 23:26
A simple QR code scanner using Vision for iOS (Swift)
import UIKit
import Vision
import AVFoundation
import Foundation
class ScanViewController: UIViewController {
private lazy var cameraPreviewLayer: AVCaptureVideoPreviewLayer = {
let l = AVCaptureVideoPreviewLayer(session: captureSession)
l.videoGravity = .resizeAspectFill
l.connection?.videoOrientation = .portrait
@nikbabchenko
nikbabchenko / counter.js
Created September 7, 2021 07:41
Counter
const counter = createCounter(); // { increment: Function, decrement: Function, value: Number }
counter.increment();
counter.value
@nikbabchenko
nikbabchenko / async.js
Created September 7, 2021 08:16
async execution task
console.log('start')
setTimeout(() => {
console.log('setTimeout')
})
Promise.resolve().then(() => {
console.log('resolve')
})
console.log('end')
@nikbabchenko
nikbabchenko / get-news.js
Last active May 14, 2024 03:04
Promises task
const news = [
"https://jsonplaceholder.typicode.com/posts/1",
"https://jsonplaceholder.typicode.com/posts/2",
"https://jsonplaceholder.typicode.com/posts/3",
"https://jsonplaceholder.typicode.com/posts/4",
"https://jsonplaceholder.typicode.com/posts/5",
"https://jsonplaceholder.typicode.com/posts/6",
"https://jsonplaceholder.typicode.com/posts/7",
"https://jsonplaceholder.typicode.com/posts/8",
"https://jsonplaceholder.typicode.com/posts/9",
@nikbabchenko
nikbabchenko / duck-typing.ts
Created October 11, 2021 11:37
Typescript duck typing
class Dog {
sound = "barking";
}
class Lion {
sound = "roaring";
}
const b: Lion = new Dog();

MongoDB Cheat Sheet

Show All Databases

show dbs

Show Current Database

@nikbabchenko
nikbabchenko / polling-fix.ts
Created September 6, 2022 10:16
Fix polling
public poll$<T>(
request$: () => Observable<T>,
delayTime: number = this.getPollingInterval()
): Observable<T> {
return interval(delayTime).pipe(
switchMap(() => request$())
);
}
@nikbabchenko
nikbabchenko / links.sh
Created June 20, 2023 13:38
npm link