Skip to content

Instantly share code, notes, and snippets.

View chrisweight's full-sized avatar

Chris Weight chrisweight

View GitHub Profile
import UIKit
struct Downsampler {
// MARK: - functions
static func downsampleImage(imageURL: URL, frameSize: CGSize,
scale: CGFloat = UIScreen.main.scale) -> UIImage? {
/// creates an CGImageSource that represent an image
let imageSourceOptions = [kCGImageSourceShouldCache: false] as CFDictionary
guard let imageSource = CGImageSourceCreateWithURL(imageURL as CFURL, imageSourceOptions) else {
@splitinfinities
splitinfinities / example.js
Created September 22, 2021 18:41
Examples of Stencil's Stats
// With some bundler parser with Webpack or Rollup:
import json from "./stencil-stats.json"
// or with CSS Import Assertions:
// import json from "./stencil-stats.json" assert { type: "json" };
export const get_preload_tags = (components, format = "esmBrowser") => {
const entries = json.formats[format];
const set = components.map((element) => {
let files = [];
@mbforbes
mbforbes / minimal-ecs.ts
Created September 5, 2021 06:50
A minimal but complete Entity Component System (ECS) implementation in 99 lines.
type Entity = number
abstract class Component { }
abstract class System {
public abstract componentsRequired: Set<Function>
public abstract update(entities: Set<Entity>): void
public ecs: ECS
}
type ComponentClass<T extends Component> = new (...args: any[]) => T
class ComponentContainer {
private map = new Map<Function, Component>();
import {
EventObject,
StateMachine,
InterpreterOptions,
MachineOptions,
StateConfig,
interpret,
Actor,
} from 'xstate'
import { from, BehaviorSubject, Observable, merge } from 'rxjs'
@peterreisz
peterreisz / index.js
Last active May 30, 2024 10:00
Dev server proxy for stencil. Backend is running on port 3000, stencil on 3333, open port 5000 for development. Only `/api` requests are sent to the backend, everything else served by stencil.
const http = require('http');
const httpProxy = require('http-proxy');
const proxyApi = new httpProxy.createProxyServer({
target: {
host: '127.0.0.1',
port: 3000
}
});
proxyApi.on('error', () => {});
@timothycosta
timothycosta / UIScrollViewWrapper.swift
Created July 5, 2019 03:25
UIScrollView wrapped for SwiftUI
//
// UIScrollViewWrapper.swift
// lingq-5
//
// Created by Timothy Costa on 2019/07/05.
// Copyright © 2019 timothycosta.com. All rights reserved.
//
import SwiftUI
//
// CameraController.swift
//
import AVFoundation
import Photos
import UIKit
class CameraController: UIViewController {
enum Camera {
@JofArnold
JofArnold / Login.m
Last active October 26, 2022 13:31
Using promises in React Native modules with Swift
// Created by react-native-create-bridge
// import RCTBridgeModule
#if __has_include(<React/RCTBridgeModule.h>)
#import <React/RCTBridgeModule.h>
#elif __has_include(“RCTBridgeModule.h”)
#import “RCTBridgeModule.h”
#else
#import “React/RCTBridgeModule.h” // Required when used as a Pod in a Swift project
#endif
@peterbsmyth
peterbsmyth / recipe.example.md
Last active May 21, 2020 13:39
Making chained API Calls using @ngrx/Effects

Making chained API Calls using @ngrx/Effects

Purpose

This recipe is useful for cooking up chained API calls as a result of a single action.

Description

In the below example, a single action called POST_REPO is dispatched and it's intention is to create a new repostiory on GitHub then update the README with new data after it is created.
For this to happen there are 4 API calls necessary to the GitHub API:

  1. POST a new repostiry
  2. GET the master branch of the new repository
  3. GET the files on the master branch
@bigearsenal
bigearsenal / URLProtocol + URLSession.swift
Last active February 14, 2024 14:09
Custom URLProtocol with URLSession
//
// MyURLProtocol.swift
// NSURLProtocolExample
//
// Created by Chung Tran on 26/08/2017.
// Copyright © 2017 Zedenem. All rights reserved.
//
import UIKit
var requestCount = 0