Skip to content

Instantly share code, notes, and snippets.

View dancollins's full-sized avatar

Dan Collins dancollins

View GitHub Profile
#!/bin/sh
# Copyright, 2012 Axel Heider
#
# Based on scrpts from
# Sebastian P.
# Nicholas A. Schembri State College PA USA
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
#!/bin/sh
# Copyright 2008 Nicholas A. Schembri State College PA USA
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
@dancollins
dancollins / X macros
Created April 7, 2015 08:51
Simple demo showing how X macros can be used to generate an enumeration as well as a string array mapped to that enumeration
/*
* This demo shows how preprocessor macros (formally called X macros) can be
* used to convert one list into both an enumeration and an array of strings.
* This is really useful for converting an enum value into a readable form.
*
* Dan Collins 2015
*/
#include <stdlib.h>
#include <stdio.h>
105c105,106
< subprocess.check_output(["pgrep", "spotify"])
---
> pgrep_out = subprocess.check_output(["pgrep", "spotify"])
> self.pids = pgrep_out.decode('utf-8').split()
284c285
< pids = pidof_out.decode("utf-8").strip().split(" ")
---
> #pids = pidof_out.decode("utf-8").strip().split(" ")
294c295
@dancollins
dancollins / gist:3945393
Created October 24, 2012 10:38
Microchip Application Library Gem
/* Continue the loop till you find SPI Baud Rate Register Value */
while (1) {
/* SPI Clock Calculation as per PIC32 Manual */
SPI_Clk_Freq = pbFreq / (2 * (SPI_Brg + 1));
if (SPI_Clk_Freq <= MAX_SPI_CLK_FREQ_FOR_P2P)
break;
SPI_Brg++;
}
@dancollins
dancollins / gist:3824166
Created October 3, 2012 00:17
Sort names by reversed first name
'''
Given a list of names, this program will sort them by the last letter of their first name.
It does this by reversing their first name, and sorting a dictionary like that.
Dan Collins 2012
'''
import operator
names = ['Andrew Hornblow', 'Bobby', 'Bruce Lee', 'Dan Collins', 'Fabian Cook', 'Matthew', 'Ross Petersen'] # Names to sort
@dancollins
dancollins / gist:3803411
Created September 29, 2012 07:12
Output from EEPROM read
Starting EEPROM read of 42 bytes.
Opening Addr value: 0
Addr: 0 Byte: 3
Addr: 1 Byte: 7
Addr: 2 Byte: 4
Addr: 3 Byte: 7
Addr: 4 Byte: .
Addr: 50 Byte: 2
Addr: 13619 Byte: 5
Addr: 13620 Byte: 7
@dancollins
dancollins / gist:3803328
Created September 29, 2012 06:06
EEPROM write which takes page boundaries into account
void ee_write(char * buf, unsigned int addr, unsigned int len) {
int i = 0;
ee_ackPoll(); // Wait for the EEPROM to be ready
sprintf(bf1, "Starting EEPROM write of %d bytes.\r\n", len);
debugr(bf1);
while(len > 0) { // Write all of the bytes to the EEPROM
IdleI2C1();
@dancollins
dancollins / gist:3803317
Created September 29, 2012 05:58
This is the EEPROM read function. Output is: https://gist.github.com/3803316
void ee_read(char * buf, unsigned int addr, unsigned int len) {
unsigned int i;
sprintf(bf1, "Starting EEPROM read of %u bytes.\r\n", len);
debugr(bf1);
IdleI2C1();
StartI2C1();
WriteI2C1(EE_ADDR | EE_W);
IdleI2C1();
@dancollins
dancollins / gist:3803316
Created September 29, 2012 05:58
Output from EEPROM read
Starting EEPROM read of 42 bytes.
Addr: 0 Byte: 3
Addr: 1 Byte: 7
Addr: 2 Byte: 4
Addr: 3 Byte: 7
Addr: 4 Byte: .
Addr: 32 Byte: 2
Addr: 3533 Byte: 5
Addr: 3534 Byte: 7
Addr: 3535 Byte: 8