Pages

Sunday, January 30, 2011

Mercurial hgrc for insecure push

[web]
allow_push = *
push_ssl = false


Setting up mercurial init.d web serving

cd /usr/lib/cgi-bin
cp /usr/share/doc/mercurial-common/examples/hgweb.cgi .
chown www-data:www-data hgweb.cgi
chmod u+x hgweb.cgi

comment the last two lines of hgweb.cgi and add the following:
#application = hgweb("/data/hg/test", "repository name")
#wsgicgi.launch(application)
from mercurial.hgweb.hgweb_mod import hgweb
from mercurial.hgweb.hgwebdir_mod import hgwebdir
from mercurial.hgweb.request import wsgiapplication

def make_web_app():
    return hgwebdir("/usr/lib/cgi-bin/hgweb.config")

application = wsgiapplication(make_web_app)
wsgicgi.launch(application)

create: hgweb.config
[collections]
/data/hg = /data/hg

Add the following to: /etc/apache2/sites-enabled/000-default
ScriptAlias /hg "/usr/lib/cgi-bin/hgweb.cgi"

http://www.aventinesolutions.nl/mediawiki/index.php/Quick_Tip:_Getting_Started_with_Mercurial

http://mercurial.selenic.com/wiki/PublishingRepositories#single


http://mercurial.selenic.com/wiki/PublishingRepositories
(Also includes resources for digest as well as allowing no pass on clone/pull, but restricting push.

7.4.1. Restrict to known users

This configuration restricts access to a known set of users as defined in the /home/user/hg/hgusers password file:



AuthType Basic
AuthName "Mercurial repositories"
AuthUserFile /home/user/hg/hgusers
Require valid-user


Since the AuthType directive is set to Basic, passwords are communicated as plain text, and it is therefore recommended that this only be used with a server configured for HTTPS. See the Apache SSL documentation for more information

http://mercurial.selenic.com/wiki/FAQ

4.22. How can I store my HTTP login once and for all ?

You can specify the usename and password in the URL like:

http://user:password@mydomain.org
Then add a new entry in the paths section of your hgrc file. With Mercurial 1.3 you can also add an auth section to your hgrc file:


[auth]
example.prefix = https://hg.example.net/
example.username = foo
example.password = bar


Prevent the certificate error
http://kiln.stackexchange.com/questions/2816/mercurial-certificate-warning-certificate-not-verified-web-cacerts

SSL Configuration

http://www.tc.umn.edu/~brams006/selfsign.html

http://www.tc.umn.edu/~brams006/selfsign_ubuntu.html


cd /opt/openssl
openssl genrsa -des3 -out server.key 4096
openssl req -new -key server.key -out server.csr
openssl x509 -req -days 365 -in server.csr -signkey server.key -out server.crt
# Make a copy of the server key that does not require the password
openssl rsa -in server.key -out server.key.insecure
mv server.key server.key.secure
mv server.key.insecure server.key

# server.crt: The self-signed server certificate.
# server.csr: Server certificate signing request.
# server.key: The private server key, does not require a password when starting Apache.
# server.key.secure: The private server key, it does require a password when starting Apache.

cp server.key /etc/apache2/ssl
cp server.crt /etc/apache2/ssl
a2enmod ssl
a2ensite default-ssl


Then edit the default-ssl.conf to change the web root-- for instance /var/www-ssl. Also modify the keys to use your custom server.key and server.crt

Monday, January 24, 2011

.vmrc suggestions

set expandtab
set tabstop=4
set shiftwidth=4
set autoindent
set smartindent

Tuesday, January 18, 2011

Time machine backup



#!/bin/sh

S=`date +%s` && rsync -azv --exclude=.Trash --exclude=Library/Caches --link-dest=/data/macbook/current /Users/matt/ 192.168.1.88:/data/macbook/$S && ssh 192.168.1.88 "rm /data/macbook/current && ln -fs /data/macbook/$S /data/macbook/current"



better than this on below because it allows for failure recovery...



#!/bin/sh

S=`date +%s` && ssh 192.168.1.xx "mv /data/macbook/current /data/macbook/$S" && rsync -azv --exclude=Library/Caches --link-dest=/data/macbook/$S /Users/matt/ 192.168.1.xx:/data/macbook/current

Wednesday, January 5, 2011

Monday, January 3, 2011

Handy mercurial serve settings

This is required when using hg serve for simple sharing.

.hg/hgrc

[web]
push_ssl = false
allow_push = *

Saturday, January 1, 2011

Processing/Arduino Serial Communication (LED Dimmer)

http://www.arduino.cc/en/Tutorial/Dimmer

I made some modifications to the sample to play around with it.

I have a couple of problems.

1) I cannot figure out how to send a byte (numeric) through a tty emulator -- the emulator picks up the ascii values for each character.  It would be nice to be able to just send a numeric if possible.
2) You can only have one thing at a time connected to the tty port.  Makes sense, I just didn't think about it when I tried to use the Arduino serial monitor while my Processing application was attached.
3) The 64 bit Linux compatibility with processing serialrxtx (fixed in another post.)

Arduino CODE

/*
  Dimmer
 
 Demonstrates the sending data from the computer to the Arduino board,
 in this case to control the brightness of an LED.  The data is sent
 in individual bytes, each of which ranges from 0 to 255.  Arduino
 reads these bytes and uses them to set the brightness of the LED.
 
 The circuit:
 LED attached from digital pin 9 to ground.
 Serial connection to Processing, Max/MSP, or another serial application
 
 created 2006
 by David A. Mellis
 modified 14 Apr 2009
 by Tom Igoe and Scott Fitzgerald
 
 This example code is in the public domain.
 
 http://www.arduino.cc/en/Tutorial/Dimmer
 
 */

const int ledPin = 9;      // the pin that the LED is attached to
const int  ledFailPin = 13;
int ctr = 0;

void setup()
{
  // initialize the serial communication:
  Serial.begin(9600);
  // initialize the ledPin as an output:
  pinMode(ledPin, OUTPUT);
  pinMode(ledFailPin, OUTPUT);
}

void loop() {
  byte brightness;

  // check if data has been sent from the computer:
  if (Serial.available()) {

    digitalWrite(ledFailPin, LOW);
    // read the most recent byte (which will be from 0 to 255):
    brightness = Serial.read();
   
    // set the brightness of the LED:
    analogWrite(ledPin, brightness);
   
   char s[4];
   snprintf(s, 4, "%d", brightness);

   Serial.print("Success ");
   Serial.print(s);
   Serial.println();
  }else{
      if(ctr++ % 20000 == 0){
           Serial.print("Fail");
   Serial.println();
    digitalWrite(ledFailPin, HIGH);
      }
  }
 
}

Processing CODE
 // Processing code for this example
 // Dimmer - sends bytes over a serial port
 // by David A. Mellis
 //This example code is in the public domain.
 
 import processing.serial.*;
 Serial port;
 int lastSent=-1;
 
 void setup() {
 size(256, 150);
 
 println("Available serial ports:");
 println(Serial.list());
 
 // Uses the first port in this list (number 0).  Change this to
 // select the port corresponding to your Arduino board.  The last
 // parameter (e.g. 9600) is the speed of the communication.  It
 // has to correspond to the value passed to Serial.begin() in your
 // Arduino sketch.
 port = new Serial(this, Serial.list()[0], 9600); 
 
 // If you know the name of the port used by the Arduino board, you
 // can specify it directly like this.
 //port = new Serial(this, "COM1", 9600);
 }
 
 void draw() {
 // draw a gradient from black to white
 for (int i = 0; i < 256; i++) {
 stroke(i);
 line(i, 0, i, 150);
 }
 
 // write the current X-position of the mouse to the serial port as
 // a single byte
 int tmpX = mouseX;
 if(tmpX != lastSent){
   port.write(tmpX);
   lastSent = tmpX;
 }
 
   if (port.available() > 0) {
    String inBuffer = port.readString();  
    if (inBuffer != null) {
      println(inBuffer);
    }
  }

 }

Using Linux 64-bit with processing serial rxtx library

http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1239099636/12

sudo apt-get install librxtx-java
ln -sf /usr/lib/librxtxSerial.so lib/librxtxSerial.so