Skip to content

Instantly share code, notes, and snippets.

View h2non's full-sized avatar

Tom h2non

  • Dissident
  • Decentralized
View GitHub Profile
@h2non
h2non / issubsubclass.py
Last active December 30, 2016 00:15
Python metaprogramming for the win! Simple function to check is a given class has a subclass in the subclasses hierarchy chain.
def issubsubclass(cls, subcls):
"""
Recursively check if a given class has a subclass of `obj` class in the
subclasses hierarchy.
Under the hood, it does some metaprogramming magic recursively checking
the `__bases__` magic attribute.
Extends `issubclass` built-in function to check subclass hierarchies.

Keybase proof

I hereby claim:

  • I am h2non on github.
  • I am h2non (https://keybase.io/h2non) on keybase.
  • I have a public key whose fingerprint is F261 06C4 A327 FE10 8FE2 37B9 E63F AD85 FCFF 12F8

To claim this, I am signing this object:

@h2non
h2non / json-post.swift
Last active September 11, 2022 01:38
JSON POST example with Alamofire
let parameters = [
"username": "foo",
"password": "123456"
]
Alamofire.request(.POST, "https://httpbin.org/post", parameters: parameters, encoding: .JSON)
// -> HTTP body: {"foo": [1, 2, 3], "bar": {"baz": "qux"}}
@h2non
h2non / jargon.md
Last active April 22, 2016 06:56 — forked from cb372/jargon.md
Category theory jargon cheat sheet

Category theory jargon cheat sheet

A primer/refresher on the category theory concepts that most commonly crop up in conversations about Scala or FP. (Because it's embarassing when I forget this stuff!)

I'll be assuming Scalaz imports in code samples, and some of the code may be pseudo-Scala.

Functor

A functor is something that supports map.

@h2non
h2non / permute-characters.js
Last active September 1, 2015 18:44
Recursive implementation of string characters permutation covering all possible cases without duplication
/**
* Recursive implementation of string characters permutation
* covering all possible cases without duplication
*/
function permute(str) {
var stack = []
if (str.length === 1) {
return [ str ]
}
@h2non
h2non / bimg-test.go
Last active August 29, 2015 14:24
Gist for issue: https://github.com/h2non/bimg/issues/44. Run: go run bimg-test.go
package main
import (
"fmt"
"gopkg.in/h2non/bimg.v0"
"os"
)
const operations = 10000
@h2non
h2non / s3-putObject.js
Created May 4, 2015 17:13
Simple example demostrating how to wrap the S3.putObject() in AWS node.js SDK to transform it into a pipeable compatible interface. Related issue: https://github.com/aws/aws-sdk-js/issues/588
var fs = require('fs')
var pipefy = require('pipefy')
var AWS = require('aws-sdk')
var s3 = new AWS.S3()
// Keep safe the original function with proper scope
var putObject = s3.putObject.bind(s3)
// Override the function
s3.putObject = function (opts, cb) {
@h2non
h2non / libvips_cache_trace_out.log
Last active August 29, 2015 14:19
libvips cache trace output. Merges both stdout and stderr
This file has been truncated, but you can view the full file.
vips cache : jpegload_buffer buffer=VIPS_TYPE_BLOB, data = 0xc20818e000, length = 877585 access=((VipsAccess) VIPS_ACCESS_SEQUENTIAL) -
vips cache : jpegload_buffer buffer=VIPS_TYPE_BLOB, data = 0xc208358000, length = 877585 access=((VipsAccess) VIPS_ACCESS_SEQUENTIAL) -
vips cache+: jpegload_buffer buffer=VIPS_TYPE_BLOB, data = 0xc20818e000, length = 877585 shrink=4 -
vips cache+: jpegload_buffer buffer=VIPS_TYPE_BLOB, data = 0xc208358000, length = 877585 shrink=4 -
vips cache : copy in=((VipsImage*) 0x70191b0) -
vips cache+: shrink in=((VipsImage*) 0x70191b0) xshrink=4.000000 yshrink=4.000000 -
vips cache : copy in=((VipsImage*) 0x70197f0) -
vips cache+: shrink in=((VipsImage*) 0x70197f0) xshrink=4.000000 yshrink=4.000000 -
vips cache : copy in=((VipsImage*) 0x7019980) -
vips cache+: black width=1 height=1 bands=3 -
@h2non
h2non / debug.go
Last active August 29, 2015 14:18
package bimg
import (
"github.com/dustin/go-humanize"
. "github.com/tj/go-debug"
"runtime"
"strconv"
"time"
)
@h2non
h2non / libvips-installer.sh
Last active October 3, 2023 20:07
libvips 7.42.x cross-platform simple installer script (supports OSX, Debian, Ubuntu, CentOS, Fedora, Amazon Linux)
#!/bin/sh
#
# Orinally made by Lovell Fuller for sharp
# https://github.com/lovell/sharp
#
# Usage:
# curl -s https://gist.githubusercontent.com/h2non/89bb2f87c6499d0b25f1/raw/bf3d0743107f02f5db2b93c53f7f0e07a1c33112/libvips-installer.sh | sudo bash -
#