Skip to content

Instantly share code, notes, and snippets.

Catfish-Man / sethack.m
Created Mar 11, 2016
Demonstrating the trick of using stack-allocated mimics and sets for lookup tables instead of heap allocated keys and dictionaries
View sethack.m
// Compile with clang -framework Foundation sethack.m
#import <Foundation/Foundation.h>
#import <objc/runtime.h>
CFHashBytes from
#define ELF_STEP(B) T1 = (H << 4) + B; T2 = T1 & 0xF0000000; if (T2) T1 ^= (T2 >> 24); T1 &= (~T2); H = T1;
Dref360 /
Last active Aug 3, 2020
Difference of stuctural similarity using Tensorflow and keras. Works ONLY on tf >= 0.11
import keras.backend as K
import tensorflow as tf
class Model:
def __init__(self,batch_size):
self.batch_size = batch_size
def loss_DSSIS_tf11(self, y_true, y_pred):
"""Need tf0.11rc to work"""
y_true = tf.reshape(y_true, [self.batch_size] + get_shape(y_pred)[1:])
y_pred = tf.reshape(y_pred, [self.batch_size] + get_shape(y_pred)[1:])
View Adversarial variational bayes toy example.ipynb
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
iikuy / gist:8115191
Last active Nov 9, 2020
producer-consumer in C++11
View gist:8115191
#include <thread>
#include <iostream>
#include <queue>
std::mutex mx;
std::condition_variable cv;
std::queue<int> q;
bool finished = false;
yconst / NSArray+Statistics.h
Last active Nov 10, 2020 — forked from justinmstuart/NSArray+Statistics.m
Basic statistics for NSArrays
View NSArray+Statistics.h
@interface NSArray (Statistics)
- (NSNumber *)calculateStat:(NSString *)stat;
- (NSNumber *)sum;
- (NSNumber *)mean;
- (NSNumber *)min;
Nyx0uf / gist:217d97f81f4889f4445a
Last active Nov 15, 2020
UIImage scale using vImage
View gist:217d97f81f4889f4445a
// Create a vImage_Buffer from the CGImage
CGImageRef sourceRef = self.CGImage;
vImage_Buffer srcBuffer;
vImage_CGImageFormat format = {
.bitsPerComponent = 8,
.bitsPerPixel = 32,
.colorSpace = NULL,
.bitmapInfo = (CGBitmapInfo)kCGImageAlphaFirst,
phatmann / ImageAttachment
Created Mar 22, 2015
NSTextAttachment that scales and aligns image
View ImageAttachment
// Created by Tony Mann on 3/22/15.
// Copyright (c) 2015 7Actions. All rights reserved.
// Adapted from
import UIKit
class ImageAttachment: NSTextAttachment {
var verticalOffset: CGFloat = 0.0
nigeljyng /
Last active Feb 10, 2021 — forked from cbaziotis/
Keras Layer that implements an Attention mechanism, with a context/query vector, for temporal data. Supports Masking. Follows the work of Yang et al. [] "Hierarchical Attention Networks for Document Classification"
class AttentionWithContext(Layer):
Attention operation, with a context/query vector, for temporal data.
Supports Masking.
Follows the work of Yang et al. []
"Hierarchical Attention Networks for Document Classification"
by using a context vector to assist the attention
# Input shape
3D tensor with shape: `(samples, steps, features)`.
# Output shape
stormraiser /
Last active Mar 4, 2021
Danbooru Faces dataset

Danbooru Faces v0.1


This dataset contains ~443k anime face images of size 256x256 drawn by ~7,000 artists, obtained from Danbooru


We first downloaded JSON files of all existing posts numbered from 1 to 2,800,000 using their API. We filtered the posts by the following criteria:

luca-bernardi / AVAsset+VideoOrientation.h
Created Feb 23, 2013
Find the video orientation of an AVAsset. (Useful if you need to send the video to a remote server)
View AVAsset+VideoOrientation.h
// AVAsset+VideoOrientation.h
// Created by Luca Bernardi on 19/09/12.
// Copyright (c) 2012 Luca Bernardi. All rights reserved.
#import <AVFoundation/AVFoundation.h>
typedef enum {
LBVideoOrientationUp, //Device starts recording in Portrait