Tmux with native scrollback

Here is how to get colors working and allow native scrollback in terminal.app

file: .tmux.conf

# Show colors 
set -g default-terminal "xterm-color"
# Allow native scroll back in terminal.app 
set -g terminal-overrides 'xterm*:smcup@:rmcup@'

Show sort hostname in tab title of tmux. Really helpful trick.

file: .bashrc

case "$TERM" in
   xterm-color)
       PROMPT_COMMAND="printf '\033k$(hostname -s)\033\\';"${PROMPT_COMMAND}
       ;;
esac

Share shell history across multiple sessions

I always wanted to sync history of my all shell session.

export HISTCONTROL=ignoredups:erasedups # no duplicate entries
export HISTSIZE=100000 # big big history
export HISTFILESIZE=100000 # big big history
shopt -s histappend # append to history, don't overwrite it

# Save and reload the history after each command finishes
export PROMPT_COMMAND="history -a; history -c; history -r; $PROMPT_COMMAND"

Grab the net with Arduino

How to access a website with multiple virtual hosts from Arduino Ethernet Shield. The problem is if you have used Arduino Ethernet Shield, then you know that you can connect a IP, But if the IP has multiple virtual hosts, it will only connect to default virtual host. If it is commercial shared VPS, You wont be able to make your site default.

Gist is use of HTTP protocol which allows you to define host in your request on virtual host server. Here are the possible headers.

http://en.wikipedia.org/wiki/List_of_HTTP_headers

You should also provide basic debugging info like “User-Agent” etc.

#include <SPI.h>
#include <Ethernet.h>

// Enter a MAC address and IP address for your controller below.
// The IP address will be dependent on your local network:
byte mac[]            = {  0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
byte ip[]             = { 192, 168,   6,  30 };

byte server[]         = { ***, ***, 168,  16 }; // Your VPS

// Initialize the Ethernet client library
// with the IP address and port of the server
// that you want to connect to (port 80 is default for HTTP):
Client client(server, 80);

String response = "";

void setup() {
  Ethernet.begin(mac, ip);
  Serial.begin(9600);
  // Give the Ethernet shield a second to initialize
  delay(1000);
  Serial.println("Connecting...");
}

void loop() {
  if (!client.available() &amp;&amp; client.connect()) {
    Serial.println("-- Connected");
    // Make a HTTP request:
    client.println("GET /bot HTTP/1.0");
    client.println("Host: example.com");
    client.println("User-Agent: Arduino/Shishir (mail.mastermind [at] gmail.com)");
    client.println();
  }
  if (client.available()) {
    char c = client.read();
    response.concat(c);
  }
  if(!client.connected()){
    process(response);
    //Serial.print(response);
  }
  if (!client.connected() &amp;&amp; reset == 1) {
    Serial.println("disconnecting.");
    client.stop();
    response = "";
    delay(1000*10);
  }
}
void process(String response) {
  Serial.println(response);
}

IRB Console with history and logging

I spend most time with IRB or Rails/console. These are good settings on which I have settled with over the time. These will allow you to have basic logging and IRB history. Just put these in the ~/.irbrc file (If file doesn’t exist then create one).

# -*- Ruby-*-
require 'irb/completion'
require 'irb/ext/save-history'

ARGV.concat [ "--readline",
              "--prompt-mode",
              "simple" ]

# 25 entries in the list
IRB.conf[:SAVE_HISTORY] = 100

# Store results in home directory with specified file name
IRB.conf[:HISTORY_FILE] = "#{ENV['HOME']}/.irb-history"

script_console_running = ENV.include?('RAILS_ENV') &amp;&amp; IRB.conf[:LOAD_MODULES] &amp;&amp; IRB.conf[:LOAD_MODULES].include?('console_with_helpers')
rails_running = ENV.include?('RAILS_ENV') &amp;&amp; !(IRB.conf[:LOAD_MODULES] &amp;&amp; IRB.conf[:LOAD_MODULES].include?('console_with_helpers'))
irb_standalone_running = !script_console_running &amp;&amp; !rails_running

if script_console_running
  require 'logger'
  Object.const_set(:RAILS_DEFAULT_LOGGER, Logger.new(STDOUT))
end

Shishir Sharma

September 11, 2011

सागर से मोती छीनु, दीपक से ज्योति छीनु
पत्थर से आग लगा लू, सिने से राज़ चुरा लू
हाँ चुरा लूँ, चुरा लूँ, हाँ हाँ चुरा लूँ
Hawa Hawai -Saitaan

arduino-ethernet

Arduino Ethernet Shield and Webclient

First thing you do when you get a Ethernet Shield for Arduino (in my case Duemilanove). You will be uploading various example sketches. I was doing the same Ardoino was working flawlessly and then I got stuck in WebClient sketch.

I did all the things I could do.

  • Reset Arduino.
  • Reset Ethernet Shield.
  • Change Ethernet cat5 cable to shorter one.
  • Change Router setting.
  • Change MAC address in program.
  • Change last 2 octets of IP 192,168,6,xxx to 192,168,1,xxx.
  • At last Google about this issue.

Point to be noted I was able to run WebServer sketch and it was flawless. So I was sure shield is good.

With a quick google found this thread on http://www.arduino.cc.

Some one said that don’t connect google ;) . Bingo. Its Google.

Fcuk that.  But WebClient too works flawlessly.

 

 

Shishir Sharma

August 30, 2011

Mac sleep/Screen

Sleep immediately (no confirmation): Cmd-Opt-Eject
Put display to sleep: Ctrl-Shift-Eject