Skip to content

Instantly share code, notes, and snippets.

View asendra's full-sized avatar

Alberto Sendra asendra

View GitHub Profile
@asendra
asendra / motion.c
Created April 21, 2015 16:08
Simple motion
#define NOISE_THRESHOLD 10
#define DIFFERENCE_THRESHOLD 0.05
BOOL hasMoved(void *previous_buffer, void *current_buffer, int WIDTH, int HEIGHT) {
int total = WIDTH * HEIGHT;
int diff_count = 0;
int c = 0, r = 0;
for (c = 0; c < HEIGHT; ++c) {
@asendra
asendra / resize.c
Last active August 29, 2015 14:19
Simple Resize
void* resizeBuffer(void *original_buffer, int original_width, int original_height, int final_width, int final_height) {
void *resized_buffer = malloc(final_width*final_height);
double x_ratio = original_width/(double)final_width ;
double y_ratio = original_height/(double)final_height ;
double px, py ;
for (int i=0;i<final_height;i++) {
for (int j=0;j<final_width;j++) {
px = floor(j*x_ratio) ;
py = floor(i*y_ratio) ;
resized_buffer[(i*final_width)+j] = original_buffer[(int)((py*original_width)+px)] ;
@asendra
asendra / gray_yuv.c
Created April 20, 2015 11:53
Grayscale YUV rpi
//Try to some colors http://en.wikipedia.org/wiki/YUV
int chrominance_offset = userdata->width * userdata->height;
int v_offset = chrominance_offset / 4;
int chroma = 0;
if (output_buffer) {
mmal_buffer_header_mem_lock(buffer);
memcpy(output_buffer->data, buffer->data, buffer->length);
int grayOffset;
- (UITableViewCell*) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *cellIdentifier = @"optionsCell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
if (cell == nil) {
// Primera vez que se crea esta celda, no estaba inicializada aun.
cell = [[ UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
UILabel *nivelLabel = [[UILabel alloc] initWithFrame:CGRectZero];
### Keybase proof
I hereby claim:
* I am asendra on github.
* I am asendra (https://keybase.io/asendra) on keybase.
* I have a public key whose fingerprint is C695 260D 3DC2 60F9 395A 0980 FAF6 E1C9 4479 CC46
To claim this, I am signing this object:
#!/bin/bash
VM=$1
size=`sudo lvs -o lv_size --unit=b --noheadings /dev/vg_vms/ubuntu-base-vm | sed 's/^ *//'`
echo size=$size
sudo lvcreate --size=$size --name=vms-$VM vg_vms
sudo virt-resize --expand sda1 \
/dev/vg_vms/ubuntu-base-vm /dev/vg_vms/vms-$VM
mkdir -p tmp
virsh dumpxml ubuntu-base-vm > tmp/ubuntu-base-vm.xml
@interface UIView (Bryan)
- (void)updateFrame:(void (^)(CGPoint *origin, CGSize *size))block;
@end
@implementation UIView (Bryan)
- (void)updateFrame:(void (^)(CGPoint *origin, CGSize *size))block {
CGRect frame = self.frame;
@asendra
asendra / Widon't
Created April 20, 2014 05:24 — forked from PadraigK/Widon't
// Example:
//
// Widont makes the last space non-breaking
// so you don't end up with one word on its
// own.
//
// Widont makes the last space non-breaking
// so you don't end up with one word on
// its own.
//