Skip to content

Instantly share code, notes, and snippets.

@epatel
epatel / sense-camera.py
Created Oct 24, 2020
Worst camera in the world. Feed the Sense Hat (AstroPi) camera to the 8x8 LED matrix.
View sense-camera.py
#!/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
View raspberrypi-tips.txt
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 Sep 9, 2018
HTML5 countdown
View cd.html
<!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 Apr 1, 2016
Enable SIGFPE for iOS/Mac
View enable_sigfpe.m
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 Aug 29, 2015
Find Telldus devices IP (like Telldus Net)
View get-telldus-ip.sh
# 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 Feb 12, 2014
Quick and dirty timing macros
View quick-n-dirty-timer.h
#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 Dec 20, 2015
vvector.h by Linas Vepstas. A set of 2x2, 3x3 and 4x4 matrix operations macros.
View vvector.h
/*
* 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
View gist:4241968
/*
* main.cpp
*
* Created on: 08.12.2012
* Author: sk
*/
#include <iostream>
#include <windows.h>
@epatel
epatel / test.c
Created Sep 26, 2012
Demo of macro usage for code generation
View test.c
#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 Nov 18, 2011
Get the RGBA values for a pixel from an image
View get_pixel_values.m
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;