Skip to content

Instantly share code, notes, and snippets.

View fnky's full-sized avatar
⚠️
TypeError: Cannot read property 'status' of undefined.

Christian Petersen fnky

⚠️
TypeError: Cannot read property 'status' of undefined.
View GitHub Profile
@cprovatas
cprovatas / Data+PrettyPrint.swift
Created May 23, 2018 15:52
Pretty print JSON string from Data in Swift 4.1 (especially useful printing to Xcode console)
import Foundation
extension Data {
var prettyPrintedJSONString: NSString? { /// NSString gives us a nice sanitized debugDescription
guard let object = try? JSONSerialization.jsonObject(with: self, options: []),
let data = try? JSONSerialization.data(withJSONObject: object, options: [.prettyPrinted]),
let prettyPrintedString = NSString(data: data, encoding: String.Encoding.utf8.rawValue) else { return nil }
return prettyPrintedString
}
@FiloSottile
FiloSottile / 32.asm
Last active March 23, 2024 12:28
NASM Hello World for x86 and x86_64 Intel Mac OS X (get yourself an updated nasm with brew)
; /usr/local/bin/nasm -f macho 32.asm && ld -macosx_version_min 10.7.0 -o 32 32.o && ./32
global start
section .text
start:
push dword msg.len
push dword msg
push dword 1
mov eax, 4

@kangax's ES6 quiz, explained

@kangax created a new interesting quiz, this time devoted to ES6 (aka ES2015). I found this quiz very interesting and quite hard (made myself 3 mistakes on first pass).

Here we go with the explanations:

Question 1:
(function(x, f = () => x) {
@woloski
woloski / multitenant.md
Last active February 11, 2024 23:14
Multi Tenant Apps in Auth0

Multitenancy refers to a principle in software architecture where a single instance of the software runs on a server, serving multiple client-organizations (tenants)

Let's start by enumerating some multi tenant applications and understand how they handle it.

Slack

Authentication:

@jedi4ever
jedi4ever / nodejs-cluster-zero-downtime.md
Last active February 11, 2024 13:45
nodejs clustering, zero downtime deployment solutions

Clustering: The basics

The trick? pass the file descriptor from a parent process and have the server.listen reuse that descriptor. So multiprocess in their own memory space (but with ENV shared usually)

It does not balance, it leaves it to the kernel.

In the last nodejs > 0.8 there is a cluster module (functional although marked experimental)

@bvaughn
bvaughn / LICENSE.md
Last active November 9, 2023 07:13
Advanced example for manually managing subscriptions in an async-safe way using hooks

The MIT License (MIT)

Copyright © <year> <copyright holders>

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell

@allenwb
allenwb / 0Option2ConstructorSummary.md
Last active November 4, 2023 14:39
New ES6 constructor features and semantics: Alternative 2 manual super in derived classes

New ES6 Constructor Semantics and Usage Examples

Manual super: Alternative Design where subclass constructors do not automatically call superclass constructors

This Gist presents a new design of class-based object construction in ES6 that does not require use of the two-phase @@create protocol.

One of the characteristics of this proposal is that subclass constructors must explicitly super invoke their superclass's constructor if they wish to use the base class' object allocation and initialization logic.

An alternative version of this design automatically invokes the base constructor in most situations.

@juliensagot
juliensagot / NSBezierPath+cgPath.swift
Last active September 26, 2023 23:11
Convert NSBezierPath to CGPath (Swift 5.1, Xcode 11.3 (11C29))
extension NSBezierPath {
/// A `CGPath` object representing the current `NSBezierPath`.
var cgPath: CGPath {
let path = CGMutablePath()
let points = UnsafeMutablePointer<NSPoint>.allocate(capacity: 3)
if elementCount > 0 {
var didClosePath = true
@bendc
bendc / functional-utils.js
Last active September 15, 2023 12:12
A set of pure ES2015 functions aimed to make functional JavaScript more idiomatic.
// array utils
// =================================================================================================
const combine = (...arrays) => [].concat(...arrays);
const compact = arr => arr.filter(Boolean);
const contains = (() => Array.prototype.includes
? (arr, value) => arr.includes(value)
: (arr, value) => arr.some(el => el === value)
@sigsegv-mvm
sigsegv-mvm / CSGO_SavedBy.cpp
Created October 16, 2015 05:13
Reverse-engineered logic for CS:GO's "X just saved Y by killing Z" feature
// CS:GO "saved" player logic
// based on the 20151008 version of the CS:GO Linux dedicated server
//
// reverse engineering by sigsegv
// from x86 assembly to C++ with the help of a disassembler and the Source SDK
// (please don't sue me)
// terminology:
// "enemy" player who was just killed by savior