Skip to content

Instantly share code, notes, and snippets.

@olenhad
olenhad / gist:3755065
Created September 20, 2012 10:14
Cute gmail chat flood hack
var intervalId = setInterval(function teaseMina(){document.getElementsByClassName("ad3")[0].value=document.getElementsByClassName("ad3")[0].value+"\nMina"},100);
//To stop: clearInterval(intervalId);
@olenhad
olenhad / playwav.clj
Created December 16, 2012 17:05
Simple wav player using java sound
(ns sound.core
(:import (java.io File)
(javax.sound.sampled AudioFormat AudioInputStream AudioSystem DataLine DataLine$Info LineUnavailableException SourceDataLine)))
(defn play-sound [filename]
(let
[
sfile (new File filename)
ainput (AudioSystem/getAudioInputStream sfile)
aformat (.getFormat ainput)
info (DataLine$Info. SourceDataLine aformat)
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)

#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
/*
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:
// 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];
#include <iostream>
using namespace std;
class Foo
{
public:
int a;
double b;
};
@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");
},
//: Playground - noun: a place where people can play
import UIKit
var str = "Hello, playground"
enum Maybe<T> {
case Nothing
case Just(T)
}
@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>