Temperature Effects in Nuclear Quadrupole Resonance Spectroscopy

How to clone all Github repositories for a given user

It’s a hack, but it’ll work. You’ll need either:

  • Linux
  • OSX
  • Windows, running the git-bash app (highly recommended). Download it here: Git – Downloads

Making your command line prompt cool – exploring PS1, PROMPT_COMMAND and other environment variables

Let’s start with an extremely basic prompt so we can see how subtle changes affect it. If you export PS1=’a string of text’, your prompt will be exactly ‘a string of text’, unless you use one of the special PS1 codes ‘\u, \h, \w’:

Other PS1 codes include:

u - the current user's username
h - the current machine's hostname
j - the number of jobs managed by this shell
@ - the current time (12 hour format)
d - the current date
w - path of the current working directory
W - just the current working directory
e - an ASCII escape character (033)
n - adds a newline character

Adding colors is the next step. Bash reads a color code and colorizes everything after that, until it reads a new one. And I mean everything. You need to end your PS1 with the color code you want to type in.

In pseudocode,
export PS1='code1 item code2 item2 coode3 item3'

This results in item having color for “colorcode”, item2 having colorcode2, item3 having colorcode3, and we exit with colorcode4 which will be the color of your commands you type.

We can combine several codes together if they are compatible. For example, 0 is default, 1 is bold. So 1;32 means bold and yellow. \033[1;36m means, to bash “beginning a color code, make it bold, and make it cyan.” You can keep adding color codes, and if they don’t override the last one, they will just add:

echo -e '\033[1m make it bold, and \033[36m make it \033[31m red \033[31;103m with a yellow background'

My usual PS1 is: export PS1='\[\033[1;33m\]\u\[\033[0;36m\]@\[\033[1;32m\]\h\[\033[1;37m\]:\[\033[1;31m\]\w \[\033[1;96m\]\$ \[\033[0m\]', or something like this. Let’s break it down by bolding the color codes

export PS1='\[\033[1;33m\]\u\[\033[0;36m\]@\[\033[1;32m\]\h\[\033[1;37m\]:\[\033[1;31m\]\w \[\033[1;36m\]\$ \[\033[0m\]'

export PS1='\[\033[1;33m\]\u\[\033[0;36m\]@\[\033[1;32m\]\h\[\033[1;37m\]:\[\033[1;31m\]\w \[\033[1;96m\]\$ \[\033[0m\]'

The PROMPT_COMMAND environment variable executes a command each time your prompt returns to you. It can be used to give your PS1 some dynamic ability – the ability to update depending on the current state of the system, outside of the limited PS1 codes. The only way I’ve been able to use it meaningfully is to print the system memory available.

export PROMPT_COMMAND='echo -en "\033[m\033[38;5;2m"$(( `sed -n "s/MemFree:[\t ]\+\([0-9]\+\) kB/\1/p" /proc/meminfo`/1024))"\033[1;38;5;22m/"$((`sed -n "s/MemTotal:[\t ]\+\([0-9]\+\) kB/\1/Ip" /proc/meminfo`/1024 ))MB ""'

Messing with LS_COLORS

I’ll first set LS_COLOR='' Below, you’ll see that nothing is colored, except for the directories which are blue, because of another environment variable called DIR_COLORS. We are going to learn how to tell LS_COLORS to colorize files by name.

I usually had colored by files by whether or not they were executable, a symbolic link, etc, which something like LS_COLORS='di=96:fi=0:ln=33:ex=1;92' which sets

  • directories to 96 (cyan)
  • files to 0 (default)
  • links to 33 (yellow)
  • executables to 92 (green)

and so on.

I realized recently you can set LS_COLORS to colorize files by name. This is useful in times where you know many types of files will be present in a directory and you want to see what they are right away. Or even if its not that useful, it’s still pretty cool.

Here I know I have .tex, .aux, .log, .bib, .png, .zip, and .pdf all in this directory. I do LS_COLORS='*.png=96:*.aux=90:*.bib=94:*.log=1;90:*.pdf=1;93:*.tex=93:*.zip=91:di=1;94'

Notice how you can set bold and a color with 1;COLOR.


Since you can take this to extremes, I did.  I quite like it – I use colored pens in real life, so when I discovered this, I just had to …


🙂 Enjoy the pretty prompts!

Bitcoin-data manipulaton and plotting in python


plot.png - https://i0.wp.com/raw.githubusercontent.com/Altoidnerd/bitcoin-price/master/plot.png?resize=840%2C474&ssl=1
I wrote a python mini-api to manipulate and visualize the price of bitcoin historically using the coinbase version 1 api.

bitcoin-price (python module)

Get bitcoin price data from the coinbase API and parse it into an easily manipulated form.

>>> from fast_dump_v22 import *
>>> get_page(1)

Will return all the data on page 1 of coinbase’s bitcoin price API (this is the latest data).

You can almost always turn on optional debug statements

>>> get_first_N(3, show=True)
... fetching first 3

You can get all the price data that coinbase has

>>> get_all(show=True)
... getting page 1
... getting page 2
... getting page 3
... getting page 4
... getting page 5
... getting page 6
... getting page 7
... getting page 8
... getting page 9
... etc ...

All the ‘get_*’ functions return a price_data string, which is interlaced timestamps and prices littered with newlines and commas. You can print them to see what is going on more clearly:

>>> print(get_page(1))

Turn on the optional show switch for printing large vectors

>>> prices(get_page(11), show=True)
... returning 11000 prices in specified range ...

You can use prices(data)[k] and timestamps()[j] to return the kth price in data, or the jth timestamp in data.

>>> data = get_page(1)
>>> prices(data)[4]
>>> prices(data, index=4)

are two equivalent ways of returning only the 4th price in the requested range (in this case, page 1). This also works for timestamps.

>>> timestamps(get_page(1)+get_page(2))[1166] == timestamps(get_first_N(2), index=1166)

This shows the expressiveness of this module. In general:

>>> prices(get_page(2)) == parse(get_page(2))[0]

prices() and timestamps() are just functions that return a parsed() object having a specific index, or indices.

>>> parse(get_page(1)+get_page(2)+get_page(3))[0] == prices(get_first_N(3))
>>> parse(get_page(2)+get_page(3))[0] == prices(get_range(2,3))

The parse() function is there to manually control the outputs instead of just getting prices, or timestamps

>>> x = parse(get_page(1))
>>> x[0][0]
>>> x[0][1]
>>> x[1][1]

As you can see, parse(price_data)[0][k] returns the kth price in the list. Indices [1][k] return the kth timestamp.

The parse() function takes care of some weird edge cases:

>>> get_first_N(3) == get_page(1)+get_page(2)+get_page(3)
>>> parse(get_first_N(3)) == parse(get_page(1)+get_page(2)+get_page(3))
>>> x = get_page(1)
>>> y = get_range(2,7)
>>> prices(get_first_N(7)) == prices(x+y)

In general,

OPERATOR( get_page(1) + get_page(2) + ... + get_page(k) ) == OPERATOR(get_first_N(k))

where OPERATOR is parsed(), prices(), or timestamps(). We also know prices() can obviously display and return ranges of values. When returning large vectors, you can verify their length by setting show=True. The “show” parameter is optional for all get_* functions and provides some information about the operation being performed.

>>> print( prices(get_first_N(11), show=True) )
... returning 11000 prices in specified range...

since each page is a thousand pairs of values (timestamp, price).

>>> len(prices(get_page(2))
>>> prices(get_page(2)) # returns a long list

fast_dump_v1* are older versions that are somewhat different. They are designed to store the fetched data in the .data directory. This in v2*, this was abandoned in favor of stdout redirection.
// 2015 altodinerd.com