Skip to content

Instantly share code, notes, and snippets.

@olenhad
olenhad / infinite_cmd.py
Created April 1, 2020 08:20
Running a command infinitely until it succeeds
import subprocess
import sys
def run_command(command):
process = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
while True:
output = process.stdout.read(1).decode()
if output == '' and process.poll() is not None:
break
if output != '':
@olenhad
olenhad / AVAudioPCMBuffer+Additions.m
Last active January 2, 2021 02:49
Combining AVAudioPCMBuffers. Assumes non interleaved format
@implementation AVAudioPCMBuffer (LiveAdditions)
- (AVAudioPCMBuffer *)combineWithBuffer:(AVAudioPCMBuffer *)buffer {
if (![buffer.format isEqual:self.format]) {
return nil;
}
AVAudioPCMBuffer *combined = [[AVAudioPCMBuffer alloc] initWithPCMFormat:self.format frameCapacity:self.frameCapacity + buffer.frameCapacity];
combined.frameLength = self.frameLength + buffer.frameLength;
@olenhad
olenhad / LFAudioMixer.m
Created June 6, 2017 10:41
Simple Audio Mixer
//
// LFAudioMixer.m
// Garena
//
// Created by Omer Iqbal on 8/3/17.
// Copyright © 2017 Garena. All rights reserved.
//
#import "LFAudioMixer.h"
#import <AVFoundation/AVFoundation.h>
//: Playground - noun: a place where people can play
import UIKit
var str = "Hello, playground"
enum Maybe<T> {
case Nothing
case Just(T)
}
@olenhad
olenhad / scope_wtf.js
Created February 12, 2014 14:27
A Micro Treatise on Scoping in JS
var O = {
foo : function (callback){
callback();
},
bar : function () {
this.baz();
},
baz: function () {
console.log("fml");
},
#include <iostream>
using namespace std;
class Foo
{
public:
int a;
double b;
};
// The following is executed every 0.5s
CMAcceleration accel = data.acceleration;
double mag = sqrt(pow(accel.x, 2)+pow(accel.y,2)+pow(accel.z,2));
// The thresholds here are derived from manually experimenting. magnitude is in Gs. 1.0G is expected due to gravity
if (mag < 0.9275 || mag > 1.0903) {
[self incrementActiveCount];
/*
If a device has both an accelerometer and a gyroscope, Core Motion offers a device-motion service that processes raw motion data from both sensors. Device motion uses sensor fusion algorithms to refine the raw data and generate information for a device’s attitude, its unbiased rotation rate, the direction of gravity on a device, and the user-generated acceleration. An instance of the CMDeviceMotion class encapsulates all of this data. Additionally, you do not need to filter the acceleration data because device-motion separates gravity and user acceleration.[1]
[1] http://developer.apple.com/library/ios/#documentation/CoreMotion/Reference/CMDeviceMotion_Class/Reference/Reference.html#//apple_ref/doc/uid/TP40009942
*/
[_manager startDeviceMotionUpdates];
/*
the following is in a timer callback:

#Extending dogfort for real world use

##Synopsis Nodejs provides a fast, lightweight platform for web servers, popularly used in real time applications. Although its possible to make clojurescript applications targeting nodejs, the current experience is far from pleasant. Partly due to node’s heavy use of callbacks, and partly because most existing node libraries are heavily object oriented and imperative. Bodil Stokke’s dogfort (https://github.com/bodil/dogfort) is a nice proof of concept , inspired by ring and compojure, that abstracts out quite a few of these issues.

Dogfort uses ‘promises’ built on top on Node’s EventEmitter class abstracted by Bodil’s redlobster library, instead of chaining callbacks. This allows event handlers to return values which makes a ring inspired api (producing response maps from request maps) possible.

However before it can be put to real world use, Dogfort lacks a few crucial features necessary for any web server framework. This includes (and is not limited to):

  • sess
require 'rubygems'
require 'plist'
require 'yaml'
ARGV.each do |yaml_filename|
parts = yaml_filename.split(".")
filename = parts[0,parts.length-1].join(".")
plist_filename = "#{filename}.plist"
thing = YAML.load_file(yaml_filename)
Plist::Emit.save_plist(thing, plist_filename)