Skip to content

Instantly share code, notes, and snippets.

@rafacouto
rafacouto / button_flash_led.ino
Created July 31, 2014 22:41
State button and flashing led
const int LED_PIN = 3;
const int BTN_PIN = 4;
const int FLASH_MILLIS = 100;
void setup() {
pinMode(LED_PIN, OUTPUT);
pinMode(BTN_PIN, INPUT);
}
@rafacouto
rafacouto / gnome-terminal_256color
Created September 20, 2014 16:21
Fix the TERM variable to allow 256 colors in a gnome-terminal
# Fix the TERM variable to allow 256 colors in a gnome-terminal. Pretty full color in vim!
# Put this lines in your ~/.bashrc
if [ "$TERM" == "xterm" ] && [ "$COLORTERM" == "gnome-terminal" ]; then
export TERM=xterm-256color
fi
@rafacouto
rafacouto / uart_bridge.ino
Created November 16, 2014 23:31
A bridge to comunicate with an UART connected to Serial1 Arduino
void setup() {
Serial.begin(9600); // Arduino monitor
Serial1.begin(9600); // connected UART
}
void loop() {
while (true) {
while (Serial.available()) Serial1.write(Serial.read());
while (Serial1.available()) Serial.write(Serial1.read());
delay(10);
@rafacouto
rafacouto / crc16.c
Last active August 29, 2015 14:10
CRC16 CCITT implementation
// crc16.c
#include "crc16.h"
static const uint16_t ccitt_hash[] = {
0x0000,0x1021,0x2042,0x3063,0x4084,0x50a5,0x60c6,0x70e7,
0x8108,0x9129,0xa14a,0xb16b,0xc18c,0xd1ad,0xe1ce,0xf1ef,
0x1231,0x0210,0x3273,0x2252,0x52b5,0x4294,0x72f7,0x62d6,
0x9339,0x8318,0xb37b,0xa35a,0xd3bd,0xc39c,0xf3ff,0xe3de,
0x2462,0x3443,0x0420,0x1401,0x64e6,0x74c7,0x44a4,0x5485,
@rafacouto
rafacouto / git-promt-bashrc
Created December 10, 2014 12:00
Sets a prompt showing the git branch when within a git directory
# git prompt
function git-branch-name {
git symbolic-ref HEAD 2>/dev/null | cut -d"/" -f 3
}
function git-branch-prompt {
local branch=`git-branch-name`
if [ $branch ]; then printf " [%s]" $branch; fi
}
// compile: mono-csc Threads.cs
// execute: mono Threads.exe
using System;
using System.Threading;
namespace Test
{
class Threads
@rafacouto
rafacouto / light_sensor_energy_safe.ino
Last active August 29, 2015 14:16
Energia sketch to test a light sensor connected to an operational amplifier. The circuit is powered by enabling the P1.6 signal during TEST_MILLIS every EVERY_MILLIS in order to safe energy (TEST_MILLIS/EVERY_MILLIS fraction).
// Energia sketch to test a light sensor connected to an operational amplifier. The circuit
// is powered by enabling the P1.6 signal during TEST_MILLIS every EVERY_MILLIS in
// order to safe energy (TEST_MILLIS/EVERY_MILLIS fraction).
#define POWER_LED GREEN_LED /* green LED (LED2 on board) and P1.6 connected to the Vdd */
#define SENSOR_LED RED_LED /* red LED (LED1 on board) */
#define SENSOR P1_7 /* pin P1.7 connected to Vout of the operational amplifier */
#define TEST_MILLIS 1 /* milliseconds that test is enabled */
#define EVERY_MILLIS 1000 /* milliseconds of the period of test */
<?php
$a = 2;
$b = 2;
$c = 1;
$d = 1;
$e = 3;
$f = 3;
<?php
$a = 5;
$b = 5;
for ($aa = 0; $aa <= $a; $aa++)
{
for ($bb = 0; $bb <= $b; $bb++)
{
if ($aa == 0 || $bb == 0)
using System;
using System.Net;
using System.Net.Sockets;
using System.Text;
class test
{
public static void Main(String[] args)
{
string hostName = "india.colorado.edu";
int hostPort = 13;