Skip to content

Instantly share code, notes, and snippets.

@Catfish-Man
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 http://www.opensource.apple.com/source/CF/CF-1153.18/CFUtilities.c
*/
#define ELF_STEP(B) T1 = (H << 4) + B; T2 = T1 & 0xF0000000; if (T2) T1 ^= (T2 >> 24); T1 &= (~T2); H = T1;
@Dref360
Dref360 / DSSIM.py
Last active Aug 3, 2020
Difference of stuctural similarity using Tensorflow and keras. Works ONLY on tf >= 0.11
View DSSIM.py
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
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
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
Nyx0uf / gist:217d97f81f4889f4445a
Last active Nov 15, 2020
UIImage scale using vImage
View gist:217d97f81f4889f4445a
-(UIImage*)mmg_imageScaledToFitSize:(CGSize)fitSize
{
// 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
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 http://ossh.com.au/design-and-technology/software-development/implementing-rich-text-with-images-on-os-x-and-ios/
import UIKit
class ImageAttachment: NSTextAttachment {
var verticalOffset: CGFloat = 0.0
@nigeljyng
nigeljyng / AttentionWithContext.py
Last active Feb 10, 2021 — forked from cbaziotis/AttentionWithContext.py
Keras Layer that implements an Attention mechanism, with a context/query vector, for temporal data. Supports Masking. Follows the work of Yang et al. [https://www.cs.cmu.edu/~diyiy/docs/naacl16.pdf] "Hierarchical Attention Networks for Document Classification"
View AttentionWithContext.py
class AttentionWithContext(Layer):
"""
Attention operation, with a context/query vector, for temporal data.
Supports Masking.
Follows the work of Yang et al. [https://www.cs.cmu.edu/~diyiy/docs/naacl16.pdf]
"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
stormraiser / danbooru_faces.md
Last active Mar 4, 2021
Danbooru Faces dataset
View danbooru_faces.md

Danbooru Faces v0.1

Discription

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

Collection

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
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