Skip to content

Instantly share code, notes, and snippets.

View darkredz's full-sized avatar

Leng Sheng Hong darkredz

View GitHub Profile
@darkredz
darkredz / gist:3142557
Created July 19, 2012 09:17
iOS Silent Switch with AIR 3.4
import flash.media.SoundMixer;
import flash.media.AudioPlaybackMode;
SoundMixer.audioPlaybackMode = AudioPlaybackMode.AMBIENT;
@darkredz
darkredz / gist:3152203
Created July 20, 2012 17:49
JS expression query in MongoDB with DooPHP
<?php
//this would be slow to find case insensitive category
$categoryInput = strtolower($postedFromSomeWhere);
$categoryModel = new Category;
$rs = $categoryModel->findOne(
'$where' => 'this.category.toLowerCase()=="'. $categoryInput .'" && this.username=="leng"'
);
@darkredz
darkredz / gist:3152294
Created July 20, 2012 18:02
Using MongoRegex vs Javascript Expression $where
<?php
//With proper Indexing this will be a lot faster than JS Expression
$categoryInput = strtolower($postedFromSomeWhere);
$categoryInput = preg_quote($categoryInput);
$regex = new MongoRegex ('/^'. $categoryInput .'$/i');
$categoryModel = new Category;
$rs = $categoryModel->findOne(
'username' => 'leng',
@darkredz
darkredz / gist:3162836
Created July 23, 2012 09:43
Autoplaying Youtube HTML5 Player in UIWebView air native extension
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html><head>
<META http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<style>body{margin:0px;}</style>
</head>
<body>
<!-- 1. The <div> tag will contain the <iframe> (youtube video player) -->
<div id="player"></div>
<script>
@darkredz
darkredz / gist:4531702
Last active December 11, 2015 02:38
Full size video player using UIWebView ANE
protected function view1_viewActivateHandler(event:ViewNavigatorEvent):void
{
if(fsVideo) return;
fsVideo = new VideoPlayer(stage, new Rectangle(0,0,stage.stageWidth, stage.stageHeight));
//this will auto play and enter full screen mode
fsVideo.initAndLoad("videos/IKH5zGaSIfs_c.mp4","video/mp4",true,false,false,false);
//make video player fullsize (width and height covers full stage size)
@darkredz
darkredz / AS3 conditional compilation
Created April 2, 2013 16:27
AS3 conditional compilation
//additional compiler options: -define+=DEFINE::IOS,true
package
{
DEFINE::IOS
{
// import some IOS only stuff
}
<!DOCTYPE html>
<html>
<head>
<style>body{margin:0px 0px 0px 0px;}</style>
</head>
<body>
<div id="player"></div>
<script>
var tag = document.createElement('script');
tag.src = "http://www.youtube.com/player_api";
@darkredz
darkredz / youtube-inline-UIWebView
Created April 8, 2013 05:26
Play Youtube Video Inline within webpage (iOS iPhone) using UIWebView ANE for Adobe AIR
<!DOCTYPE html>
<html>
<body>
<div id="player"></div>
<script>
var tag = document.createElement('script');
tag.src = "//www.youtube.com/iframe_api";
var firstScriptTag = document.getElementsByTagName('script')[0];
firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);
public function init():void{
nativeWeb = new UIWebView();
nativeWeb.stage = stage;
nativeWeb.viewPort = new Rectangle(0,0,1024,748);
nativeWeb.loadURL('http://darkredz.com')
button.addEventListener(MouseEvent.CLICK, onClick)
nativeWeb.addEventListener(PrintJobEvent.COMPLETE, onDone)
nativeWeb.addEventListener(PrintJobErrorEvent.ERROR, onError)
}
@darkredz
darkredz / UIWebView setAudioSession
Created April 10, 2013 19:29
Setting AudioSession mode for UIWebView and VideoPlayer class in iOS with Adobe AIR
webview = new UIWebView()
webview.setAudioSession( AudioSession.PLAYBACK )