Skip to content

Instantly share code, notes, and snippets.

View eklimcz-zz's full-sized avatar

Erik Klimczak eklimcz-zz

View GitHub Profile
@eklimcz-zz
eklimcz-zz / Touch Snippet
Created July 25, 2011 15:16
JS Touch Event Handlers
//Check for touch
var _eventType = ('ontouchstart' in window) ? "touch" : "mouse";
this.addEventHandlers = function(eventType) {
if (eventType === 'mouse') {
this._dragStartEvt = "mousedown";
this._dragStartCB = function(e) {
return self.OnMouseDown(e, e.clientX, e.clientY);
@eklimcz-zz
eklimcz-zz / js prevent scale scroll
Created July 25, 2011 16:31
js prevent scale scroll
<!-- Prevent Scale -->
<meta name="viewport" content="user-scalable=no, width=device-width" />
<!-- Prevent Default Scroll-->
<script>
function BlockMove(event) {
event.preventDefault() ;
}
</script>
@eklimcz-zz
eklimcz-zz / javascript scoller
Created July 25, 2011 16:36
iOS Fixed Position Scroller with Ease
/*-----------------------------------------
Usage
var list = document.getElementById('dataList'); //Any Div with Items in it
Scroller.init(list, 'x', _hasTouch); //'x' or 'y'
-----------------------------------------------*/
var Scroller = new
function() {
//Public Properties
@eklimcz-zz
eklimcz-zz / js requestAniFrame snippet
Created July 25, 2011 16:58
requst Animation frame shim
// shim layer with setTimeout fallback
window.requestAnimFrame = (function(){
return window.requestAnimationFrame ||
window.webkitRequestAnimationFrame ||
window.mozRequestAnimationFrame ||
window.oRequestAnimationFrame ||
window.msRequestAnimationFrame ||
function(/* function */ callback, /* DOMElement */ element){
window.setTimeout(callback, 1000 / 60);
};
@eklimcz-zz
eklimcz-zz / css3d Transform utility
Created July 25, 2011 18:28
css3d Transform helper
/*--------------------
Usage:
if (Modernizr.csstransforms3d) {
this.set3dTransform(this.scroller, xValue + "px", yValue + "px");
this.set3dTransform(this.parallaxBg, xValue/12 + "px", 0 + "px");
}
else{
this.set2dTransform(this.scroller, xVAlue + "px", yValue + "px");
this.set2dTransform(this.parallaxBg, xVAlue / 12 + "px", yValue + "px");
}
//---------------------HTML
<footer id="footer">
<button id="btnExpand" class="expander" type="button"></button>
...
</footer>
//---------------------CSS
footer.expander{
@eklimcz-zz
eklimcz-zz / touchEventWireup
Created September 25, 2012 16:52
Cross browser touch event wireup
function inferInputModel() {
if (window.navigator.msPointerEnabled) {
return 'pointer';
} else if (window.ontouchstart !== undefined) {
return 'touch';
} else {
return 'unknown';
}
}
@eklimcz-zz
eklimcz-zz / OpenCV2WPFConverter
Created November 21, 2012 16:21
OpenCV Image to WPF Image Converter
public static System.Drawing.Bitmap ToBitmap(this BitmapSource bitmapsource)
{
System.Drawing.Bitmap bitmap;
using (var outStream = new MemoryStream())
{
// from System.Media.BitmapImage to System.Drawing.Bitmap
BitmapEncoder enc = new BmpBitmapEncoder();
enc.Frames.Add(BitmapFrame.Create(bitmapsource));
enc.Save(outStream);
bitmap = new System.Drawing.Bitmap(outStream);
@eklimcz-zz
eklimcz-zz / KinectDepth2OpenCVImage
Created November 21, 2012 16:54
Kinect Depth Frame to OpenCV Image
Image<Bgr, Byte> openCVImg = new Image<Bgr, byte>(depthBmp.ToBitmap());
Image<Gray, byte> gray_image = openCVImg.Convert<Gray, byte>();
using (MemStorage stor = new MemStorage())
{
Contour<System.Drawing.Point> contours = gray_image.FindContours(
Emgu.CV.CvEnum.CHAIN_APPROX_METHOD.CV_CHAIN_APPROX_SIMPLE,
Emgu.CV.CvEnum.RETR_TYPE.CV_RETR_EXTERNAL,
@eklimcz-zz
eklimcz-zz / Kinect Depth Slicing
Created November 22, 2012 17:34
Kinect Depth Slicing
private const int MaxDepthDistance = 4000;
private const int MinDepthDistance = 850;
private const int MaxDepthDistanceOffset = 3150;
public static BitmapSource SliceDepthImage(this DepthImageFrame image, int min = 20, int max = 1000)
{
int width = image.Width;
int height = image.Height;
//var depthFrame = image.Image.Bits;