Skip to content

Instantly share code, notes, and snippets.

View Nillerr's full-sized avatar

Nicklas Jensen Nillerr

  • Denmark & Charlotte, NC
  • 00:08 (UTC -04:00)
View GitHub Profile
@Nillerr
Nillerr / KeyValueEntriesPipe.ts
Last active August 13, 2020 08:44
Allows the use of keyof MyType type declarations in methods accepting the keys of the entries when transformed using this pipe in an *ngFor loop.
/**
* Transforms Object into an array of key value pairs.
*/
@Pipe({ name: 'entries' })
export class KeyValueEntriesPipe implements PipeTransform {
transform<T extends { [p in keyof T]: T[keyof T] }>(input: T): { key: keyof T, value: T[keyof T] }[] {
const entries: { key: keyof T, value: T[keyof T] }[] = [];
for (const key in input) {
if (input.hasOwnProperty(key)) {
entries.push({ key, value: input[key] });
@Nillerr
Nillerr / copy-linked-frameworks.sh
Last active October 3, 2018 06:16
Automatically copies linked Carthage frameworks, without explicitly specifying them in a Run Script build phase. The script works by inspecting the executable build output using otool to create a list of dependencies, and passes them on to the `carthage copy-frameworks` script.
#!/bin/sh
frameworks=$(otool -L $BUILT_PRODUCTS_DIR/$EXECUTABLE_PATH | pcregrep -o1 "@rpath/(.*?\.framework)")
index=0
for framework in $frameworks; do
if [ -e "$SRCROOT/Carthage/Build/iOS/$framework" ]; then
export "SCRIPT_INPUT_FILE_$index"="$SRCROOT/Carthage/Build/iOS/$framework"
export "SCRIPT_OUTPUT_FILE_$index"="$BUILT_PRODUCTS_DIR/$FRAMEWORKS_FOLDER_PATH/$framework"
let index=index+1
@Nillerr
Nillerr / UIView+MainThread.swift
Last active February 26, 2022 05:46
Replaces a call to *addSubview* with an implementation that ensures it is always invoked on the main thread.
import UIKit
/**
Swizzles `addSubview` of `UIView`, replacing it with an implementatio that ensures it is always
invoked on the main thread.
Call this method in your application entry point, e.g. the `UIApplicationDelegate`.
*/
func swizzleAddSubview() {
let clazz = UIView.self
$url = "http://csgolounge.com/match?m=3071";
$id = str_replace("http://csgolounge.com/match?m=", "", $url);