Skip to content

Instantly share code, notes, and snippets.

View epatel's full-sized avatar

Edward Patel epatel

View GitHub Profile
@epatel
epatel / sense-camera.py
Created October 24, 2020 13:37
Worst camera in the world. Feed the Sense Hat (AstroPi) camera to the 8x8 LED matrix.
#!/usr/bin/python3
#
# Show camera on the sense hat.
#
# Grab a 96x64 image and then average down to 8x8 for the sense hat
#
import io
import time
Jessie -> Stretch
=================
$ sudo apt-get update
$ sudo apt-get upgrade
$ sudo apt-get dist-upgrade
$ sudo sed -i /deb/s/jessie/stretch/g /etc/apt/sources.list
$ sudo sed -i /deb/s/jessie/stretch/g /etc/apt/sources.list.d/*.list
$ sudo apt-get update
@epatel
epatel / cd.html
Last active September 9, 2018 16:19
HTML5 countdown
<!DOCTYPE html>
<html>
<head>
<meta name="apple-mobile-web-app-capable" content="yes" />
<style>
html,body {
height:100%;
}
body {
display: table;
@epatel
epatel / enable_sigfpe.m
Created April 1, 2016 11:57
Enable SIGFPE for iOS/Mac
fenv_t fe;
if (fegetenv(&fe) != 0) {
// error
}
#if defined __arm__
fe.__fpscr |= __fpscr_trap_divbyzero;
#elif defined __i386__
fe.__control &= ~FE_DIVBYZERO;
fe.__mxcsr &= ~_MM_MASK_DIV_ZERO;
@epatel
epatel / get-telldus-ip.sh
Last active August 29, 2015 14:00
Find Telldus devices IP (like Telldus Net)
# Used in Mac OS X Teminal.app (bash)
ping -c 3 255.255.255.255 | grep from | awk '{ print "ping -c 1 -q " $4; }' | sed 's/://' | sort -u | bash > /dev/null ; arp -a | grep ac:ca | sed 's/^.*(//' | sed 's/).*//'
@epatel
epatel / quick-n-dirty-timer.h
Created February 12, 2014 14:09
Quick and dirty timing macros
#include <sys/time.h>
#define START_TIMER \
struct timeval _tpStart; \
struct timeval _tpEnd; \
gettimeofday(&_tpStart, NULL)
#define STOP_TIMER \
gettimeofday(&_tpEnd, NULL); \
std::cout << "Time: " << (_tpEnd.tv_sec-_tpStart.tv_sec)+(_tpEnd.tv_usec/1000000.0-_tpStart.tv_usec/1000000.0) << "s" << std::endl
@epatel
epatel / vvector.h
Last active February 11, 2022 04:02
vvector.h by Linas Vepstas. A set of 2x2, 3x3 and 4x4 matrix operations macros.
/*
* vvector.h
*
* FUNCTION:
* This file contains a number of utilities useful for handling
* 3D vectors
*
* HISTORY:
* Written by Linas Vepstas, August 1991
* Added 2D code, March 1993
/*
* main.cpp
*
* Created on: 08.12.2012
* Author: sk
*/
#include <iostream>
#include <windows.h>
@epatel
epatel / test.c
Created September 26, 2012 05:49
Demo of macro usage for code generation
#include <stdio.h>
/* ----------------------------------------------------------------------
This part declare all structs from the "the-structs.def" file
*/
#define STRUCT_BEGIN(_name) struct _name {
#define STRUCT_END(_name) };
#define STRUCT_FIELD(_type, _name) _type _name;
@epatel
epatel / get_pixel_values.m
Created November 18, 2011 22:15
Get the RGBA values for a pixel from an image
CGImageRef image = uiimage.CGImage;
NSUInteger width = CGImageGetWidth(image);
NSUInteger height = CGImageGetHeight(image);
// Setup 1x1 pixel context to draw into
CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
unsigned char rawData[4];
int bytesPerPixel = 4;
int bytesPerRow = bytesPerPixel;
NSUInteger bitsPerComponent = 8;