Skip to content

Instantly share code, notes, and snippets.

/* Function: al_transform_rotation
*/
void al_transform_rotation(const ALLEGRO_TRANSFORM *trans, float* rotation)
{
float t = *rotation;
*rotation = t - atan2f(trans->m[0][1], trans->m[0][0]);
}
static void bitmap_source_release_content(ALLEGRO_GC_BITMAPSOURCE *bitmap_source)
{
if ( bitmap_source->type == BS_NORMAL )
{
if ( bitmap_source->name_to_bitmap )
{
/* free string key */
AL_AATREE_ITERATOR* iterator = al_aa_begin(bitmap_source->name_to_bitmap);
while (iterator && al_aa_next(iterator))
@fengye
fengye / _service.md
Last active February 18, 2018 02:30 — forked from naholyr/_service.md
Sample /etc/init.d script

Sample service script for debianoids

Look at LSB init scripts for more information.

Usage

Copy to /etc/init.d:

# replace "$YOUR_SERVICE_NAME" with your service's name (whenever it's not enough obvious)
http://pin.it/zuSovQT
@fengye
fengye / new_gist_file.js
Last active January 20, 2016 14:59
How JavaScript closure works
//From http://stackoverflow.com/questions/111102/how-do-javascript-closures-work
function sayHello2(name) {
var text = 'Hello ' + name; // Local variable
var say = function() { console.log(text); }
return say;
}
var say2 = sayHello2('Bob');
say2(); // logs "Hello Bob"
import android.media.MediaCodec;
import android.media.MediaCodecInfo;
import android.media.MediaFormat;
import android.util.Log;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
@fengye
fengye / octavetest
Last active January 21, 2017 02:16
if (midiNote > 0)
{
int octave = midiNote / 12;
int noteNum = midiNote % 12;
int normalizedNote;
if (octave % 2 == 0)
{
normalizedNote = noteNum;
}
#!/bin/bash
find -maxdepth 1 -type d | while read -r dir; do printf "%s:\t" "$dir"; find "$dir" -type f | wc -l; done
@fengye
fengye / min-char-rnn.py
Last active February 11, 2017 06:38 — forked from karpathy/min-char-rnn.py
Minimal character-level language model with a Vanilla Recurrent Neural Network, in Python/numpy
"""
Minimal character-level Vanilla RNN model. Written by Andrej Karpathy (@karpathy)
BSD License
"""
import numpy as np
# data I/O
data = open('input.txt', 'r').read() # should be simple plain text file
chars = list(set(data))
data_size, vocab_size = len(data), len(chars)
@fengye
fengye / find_similarities.py
Last active May 27, 2019 07:52
Using cross correlation to find similarity in two audios. Useful in echo cancellation.
import audio_io
import numpy
audio1, _ = audio_io.ReadWavFile('voice_nodelay.wav')
audio1 = audio1.ravel()
audio2, _ = audio_io.ReadWavFile('voice_mic_blend3.wav')
audio2 = audio2.ravel()
# Truncate all signals same length, then pad to avoid boundary effects.