timmurphy.org

Web Name: timmurphy.org

WebSite: http://timmurphy.org

ID:100683

Keywords:

timmurphy,org,

Description:

There are a number of ways to read keyboard input with python. One easy option is to use the curses library, using the getch() method, as shown below:import cursescur = curses.initscr() # initialisationtry: while True:char = cur.getch()if char 0:print("Input: " + chr(char) + "\r")except KeyboardInterrupt:print("interrupted...")curses.endwin() # cleanupprint("Goodbye :-)")The program above initialises the curses library, then sits in an infinite loop, printing a message whenever any keyboard buttons are pressed. Use ctrl-c to interrupt the loop and clean up curses before exiting gracefully. Note that if you don t run curses.endwin(), your terminal may exhibit some weird behaviour once the program finishes. LaTeX, using the pdfpages package, can insert part or all of a PDF into a document. This is useful for inserting things like surveys into an appendix. The feature can also be used to combine multiple PDFs into one document.For example, imagine we have two documents: this WHO document about the ebola outbreak in the Democratic Republic of Congo, and this WHO poster about how to hand wash. We would like to join them together but in a jumbled order, with the first page of the ebola document, followed by the hand wash poster, pages 3-5 of the ebola document, and finally, the diagram on page 2 of the ebola document. This can be done with the following code:\documentclass[a4paper]{article}\usepackage{pdfpages}\begin{document}\includepdf[pages={1}]{ebola.pdf}\includepdf[pages={-}]{hand_wash.pdf}\includepdf[pages={3-5,2}]{ebola.pdf}\end{document}This will produce a document like this one.Note the pages={...} syntax here. This can contain any number of single pages or ranges separated by a comma. Using a hyphen, as in the hand_wash.pdf line, will insert all pages. If you have a filename or list of filenames, you may want to strip the extension. There are a few ways of detecting which part of the filename is the extension, but may not work if your file has multiple extensions (e.g. .tar.gz), contains spaces or periods, or meets other weird criteria. If you know what the extension is, or at least how long it is, you can just pull those characters off the end. This can be done with the ${ varname ::0- n } syntax, which will strip n characters off the end.For example, the following code:fname=/path/to/myfile.txtecho ${fname::0-4}will print/path/to/myfile It can sometimes be useful to estimate the Snellen or logMAR acuity of a patient based on the size of the font they read at near. While there are tables available showing the conversions, this can not cover all font sizes and reading distances. With some basic trigonometry, you can do the calculations yourself.First, let s draw out the problem:Here, d is the reading distance and h is the height of the letter read by the patient. If the chart uses the N scale, the letter size is measure in points where N1 = 1 point = 1/72 inches.Let s assume the patient reads N5 (h) at a distance of 40cm (d). We need d and h to be in the same units, so we convert N5 to metric like so:N5 = 5/72 inches = 0.0694 inches1 inch = 2.54cmTherefore N5 = 0.0694 x 2.54 = 0.176cmFrom here we have a small adjustment to make; font sizes are measured as the height from the lowest tail to the highest stem or accent of any letter in that font. This is known as the em height This wikipedia article explains this concept in detail. The character | is a rough estimation of em height, but most letters are much smaller than that around the same hight as the letter x. This x-height is what we want to use in our calculation. While this differs between fonts, it is usually around half of the em height, so we multiply our value by 0.5:h = 0.176 x 0.5 = 0.088cm.So we have d = 40cm and h = 0.088cm. From here we can calculate : = atan(h/d) = atan(0.088/40) = 0.126 = 7.6 minutes of arcFinally, we need to convert to our Snellen fraction. We know than 6/6 (or 20/20) corresponds to an optotype subtending 5 minutes of arc. We can therefore calculate MAR (minimum angle of resolution) as:MAR = /5 = 7.6/5 = 1.5and from here, the logMAR and Snellen equivalents:logMAR = log(1.5) = 0.18Snellen = 6/(6xMAR) = 6/(6 1.5) = 6/9Therefore, N5 is approximately equivalent to 6/9 at a distance of 40cm. Imagine you have two text files, one with a list of names and another with a list of birth dates, which each name corresponding to the date of birth on the same line number in the other file, like so:You would like to join these files together into one file with the format name : date_of_birth . In linux, this can be done with paste, like so:paste -d':' names.txt dob.txtHere, -d is the delimiter option. This specifies which character separates data from file 1 and file 2. Running the command above produces this output:Anthony Kiedis:1-Nov-1962Flea:16-Oct-1962Chad Smith:25-Oct-1961John Frusciante:5-Mar-1970 In gnuplot, labels on the X and Y axes are aligned horizontally by default, and written over the top of each other if the labels are too long. To fix this, you can rotate the labels using the set xtics rotate [by angle ] [left|right] command. For example, you can rotate x-axis labels by 60 degrees with the following code:set xtics rotate by 60 rightWe use right alignment here, otherwise the labels run from the base of the graph upwards.The following full gnuplot code:set terminal svgset format x '%+-.6f' # to make the labels longerset xtics rotate by 60 rightplot cos(x)will generate this graph:Your browser doesn t support SVG, sorryecho "after myFunc: myvar=$myvar"The code here is fairly simple we set a variable myvar, call a function and print the value of myvar to the terminal. However, even though we don t pass myvar to the function, that value is still changed:before myFunc: myvar=1myFunc: setting myvar=123after myFunc: myvar=123Somehow, myFunc changed the value of myvar. This is because, unless specified otherwise, this variable is in the global scope. This can sometimes be useful, but it can also be confusing for programmers used to the scoping rules of other languages.To keep myvar contained to function scope only, we can use the local keyword like so:function myFunc{local myvar=123echo "myFunc: setting myvar=$myvar"}With this specified, the code behaves more like we would expect:before myFunc: myvar=1myFunc: setting myvar=123after myFunc: myvar=1 Sometimes in a Makefile you need to reference something from the directory where the Makefile lives. $(PWD) won t work in this instance, since that will return the path from where make was called which may be different if, for example, you use the --directory option. In this case, we can use the following code to find Makefile s directory:$(dir $(realpath $(firstword $(MAKEFILE_LIST))))Let s pull this apart and look at each component. For this example, our Makefile path is /tmp/path/to/my/Makefile and contains the following:include other/Makefiledefault: @echo $(PWD) @echo $(dir $(realpath $(firstword $(MAKEFILE_LIST))))First, MAKEFILE_LIST will contain all of the Makefiles which have been loaded. If you havent t included any others, only one will be listed here:$(MAKEFILE_LIST) = Makefile other/MakefileSince we re only interested in the current Makefile, we strip off the includes:$(firstword $(MAKEFILE_LIST)) = MakefileNow that we have one file, find the absolute path:$(realpath $(firstword $(MAKEFILE_LIST))) = /tmp/path/to/my/MakefileFinally, strip off the file name, leaving only the directory path:$(dir $(realpath $(firstword $(MAKEFILE_LIST)))) = /tmp/path/to/my/So, if we call make --directory=/tmp/path/to/my default from the /tmp directory, the following will be printed:/tmp/tmp/path/to/my/If you re interested in the path of the last included Makefile, use lastword instead of firstword. For example, you may use lastword from other/Makefile to find that directory. Power crosses are useful diagrams for doing lens power calculations in optics. Drawing the power crosses in LaTeX can be tedious, especially if you need to draw multiple power crosses in the same document. The code below creates a new command, \powercross{front@90}{front@180}{back@90}{back@180}, which will draw the power crosses for you and calculate the final lens power based on the powers of the front and back lens surfaces. All values will be rounded to two decimal places.Note: you need have \usepackage{fp} in the preamble in order for this code to work.% usage: \powercross{front@90}{front@180}{back@90}{back@180}\newcommand{\powercross}[4]{\setlength{\unitlength}{1mm}\vspace{1em}\begin{picture}(135,35)% crosses\multiput(0,17.5)(50,0){3}{\line(1,0){35}}\multiput(17.5,0)(50,0){3}{\line(0,1){35}}% arithmetic symbols\put(41.5,16.5){\makebox{$+$}}\put(91.5,16.5){\makebox{$=$}}% calculate resulting lens (requires fp)\FPeval{\frontninety}{round(#1:2)}\FPeval{\frontzero}{round(#2:2)}\FPeval{\backninety}{round(#3:2)}\FPeval{\backzero}{round(#4:2)}\FPeval{\lensninety}{round(\frontninety+\backninety:2)}\FPeval{\lenszero}{round(\frontzero+\backzero:2)}% labels\put(18.5,33){\makebox{{\frontninety}D}}\put(30.5,19){\makebox{{\frontzero}D}}\put(68.5,33){\makebox{{\backninety}D}}\put(80.5,19){\makebox{{\backzero}D}}\put(118.5,33){\makebox{{\lensninety}D}}\put(130.5,19){\makebox{{\lenszero}D}}\end{picture}\newline}For example, this code:\powercross{3.25}{3.25}{-10.25}{-7}will produce the following: If you re using a linux terminal and need to convert all upper case characters to lowercase, there are a number of ways you can do it. One of the easiest is to use tr:tr '[:upper:]' '[:lower:]'For example:$ echo "HeLlo WOrlD" | tr '[:upper:]' '[:lower:]'hello world:upper: and :lower: can be reversed if you want to create an upper case string instead:$ echo "HeLlo WOrlD" | tr '[:lower:]' '[:upper:]'HELLO WORLD In awk, fields are accessed by number; $1 for the first field, $2 for the second, etc. But sometimes the field number you want to access is not known until run time. In these cases, you can access the field using the $( index ) syntax. The constant NF contains the number of fields available.For example, you can print all fields with their field index like so:echo "Hello, World" | awk '{ for (i = 1; i NF; ++i) { print i, $(i); } }'The code above will print:1 Hello,2 World There are a few ways to read a file in bash, each with their own caveats. If you re looking to read a file line-by-line verbatim, including blank lines, then using a simple while loop should do the trick. For example, the following code will print the contents of a file with line numbers:line_no=0while IFS='' read -r linedo((++line_no))echo "$line_no: $line"done /etc/kdercThis will print something like:1: [Directories]2: kioskAdmin=root:3: profileDirsPrefix=/usr/share/kde-settings/kde-profile/4: userProfileMapFile=/etc/kde-user-profile5:6: [Directories-default]7: prefixes=/usr/share/kde-settings/kde-profile/default/ Sometimes it is necessary to use temporary files in your program. One concern when creating these files is thread safety; two processes creating a temporary file with the same name. This concern can be largely ignored using Java s File.createTempFile, which guarantees the file path is unique amongst all java processes running on that JVM.For example:import java.io.File;import java.io.IOException;class TempFile {public static void main(String[] args) throws IOException {File tempFile = File.createTempFile("prefix_", "_suffix");System.out.println(tempFile);}}will print something like:/var/folders/5s/wh643h2j3fqf4d7_zy_hl4fc0000gn/T/prefix_1987572090443392628_suffix Sometimes it is useful to pause a script until the user is ready to proceed. In Windows Batch scripting, this can be done with the PAUSE command. In Bash, the same thing can be done using read with the right parameters:read -rn1 -p "Press any key to continue"This command is doing the following:-r disables backslash escaping. Without this option, typing only \ will not continue execution.-n1 instructs the command to read only one character.-p "Press any key..." is the prompt, or message printed to the screen.Note that, like Batch s PAUSE command, some keys which don t result in a character being typed, like ALT, CTRL, SHIFT and CAPS LOCK, will not continue execution. Most other keys will work though. Small Angle Approximations and Skinny Triangles are concepts which simplify trigonometric calculations. The concept is based on right-angle or isosceles triangles where one side is very small compared to the other two. In these cases, some approximations can be made in place of trigonometric calculations, which may be used for estimations when information required to compute an exact value is missing, or where an estimated value is good enough.Consider the following triangle:On this right-angle triangle, the blue arc a represents the the edge of a circle if the shape was a slice of a full circle (ie: the shape bounded by the green, blue and bottom black lines would be a portion of a circle). From this, we see that r represents the radius of the circle, y is the triangle height and h is the hypotenuse. is the angle from the middle of the circle, which we represent in radians for this approximation.When = /4 (0.785 radians / 45 ) as shown above, we can t see any obvious relationship between these values:when r = 100:h = 141.4y = 100a = 78.5sin = 0.707tan = 1cos = 0.7071 ( /2) = 0.692But watch what happens as decreases (all triangles drawn to scale). = 0.464 radians (26.6 )when r = 100:h = 111.8y = 50a = 46.4sin = 0.448tan = 0.500cos = 0.8941 ( /2) = 0.892 = 0.244 radians (14.0 )when r = 100:h = 103.1y = 25a = 24.4sin = 0.242tan = 0.249cos = 0.9701 ( /2) = 0.970As you can see, for small values of :sin tan cos 1 ( /2)As approaches zero, the errors in these approximations also approach zero. As you can see, doesn t need to be that small for these approximations to be accurate enough for quick calculations. These approximations are used in a number of fields, as diverse as astronomy, optics and aircraft navigation to name a few. Awk is a useful language for many command line tasks. Often awk is used on the command line on its own or with strings piped to it, but it is possible to turn that awk code into an executable script.Consider the following script. This file contains awk code with a shebang of awk -f. The -f is important here; without it, the script won t work. The code itself is the same as you would use on the command line.#!/usr/bin/awk -f# This code will print out the users who have bash as their default shell.BEGIN {FS=":";}{if (substr($7, length($7)-3) == "bash"){print $1, "is using", $7;}}This script can then be called with an /etc/passwd style file to print the users who have bash as their default shell. For example:$ ./passwd.awk /etc/passwdroot is using /bin/bashtim is using /bin/bash If you ve made a shallow clone of a repository but suddenly find yourself needing more history, you can fetch this history using one of these two commands:All history:git fetch --unshallowOnly the last 123 updates:git fetch --depth=123For the second command, 123 can be replaced with any number. If the depth requested is larger than the history of the repository, all records will be fetched. R is quite different from most other programming languages. One common feature of other languages is the exit routine, or something with a similar name. In R, that function is stop, and takes an error message string as an argument. For example:stop("I don't work on weekends")will print:Error: I don't work on weekendsand exit the program. There are a number of software packages available for creating chemistry diagrams in LaTeX. One of those packages is ChemFig. ChemFig is a powerful package, with many features which aren t available in other packages. The syntax is fairly easy to follow once you understand the structure, but going in blind can be a bit daunting. This post will describe the basic syntax.For all examples below, \usepackage{chemfig} needs to be in the preamble. No other configuration needs to be set, and no other packages are required.Let s take a basic example, the water molecule. This can be drawn in a number of ways:\chemfig{H-O-H} will create an image that looks much like the ASCII code:This is useful for simple molecules, but it only shows the covalent bonds. If we also want to represent the angles between the bonds, we can do this in one of three ways:Add an angle step; a number between 0 and 7, where 0 means an upward (north) bond, 2 means a bond to the right (east), and so on. Each step adds 45 degrees.\chemfig{H-[1]O-[7]H}Set the angle explicitly. This angle is added to the horizontal (east) in an anti-clockwise direction, and can be negative. For example, an upward bond would have an angle of 90.\chemfig{H-[:37.75]O-[:-37.75]H}(angle here is 104.5 degrees)Set the angle relative to the previous angle (or 0 if no branches have been added).\chemfig{H-[::37.75]O-[::-75.5]H}(angle here is also 104.5 degrees)Some molecules contain a double covalent bond. These bonds can be represented using an equals sign:\chemfig{O=O}You may have noticed that each branch is taken from the last atom/sub-molecule listed, but sometimes that s not what you want. You can use brackets to indicate that no connection should be made from a branch. For example, methane can be drawn like so:\chemfig{C(-[0]H)(-[2]H)(-[4]H)(-[6]H)}With these features, you should be able to create most simple chemistry diagrams in LaTeX, such as D-glucose:\chemfig{H-[7]C(=[1]O)-[6]C(-[4]H)(-OH)-[6]C(-[4]OH)(-H)-[6]C(-[4]H)(-OH)-[6]C(-[4]H)(-OH)-[6]CH_2OH}ChemFig is much more powerful than described here. The docs on the project website are very thorough and clear, should you wish to do more than what is described here. If you ve accidentally added a git tag, or if you want to remove old tags, these tags can be removed with the following three commands:git tag -d my_tag git push origin : my_tag git push --tagsFor example, if you want to remove the tag bad_tag, you would use these commands:git tag -d bad_taggit push origin :bad_taggit push --tags Ever wanted to have a real-time clock on your linux terminal? We can create one with a single line of bash, like so:while echo -en "$(date)\r"; do sleep 1; doneLet s look at how this works:date is a common unix tool used to print the current date and time. The $(...) means that the date command is run, and the output is placed here instead. For example, if logged in as root, echo "I am $(whoami)!" is the same as echo "I am root!".echo -en will print the output of $(date). -e allows escaped characters (the \r in this case), and -n means echo will not add a newline character to the end of the line.\r is a carriage return character. This returns the cursor to the beginning of the current line, which means the next thing to print will overwrite anything on that line.while condition do commands done is a standard while loop; commands will be run while condition returns true (ie: execution is successful).sleep 1 will pause program execution for 1 second.Altogether, it means we will print the date every second, overwriting the previously printed date, until we end the program (ctrl-c) or until the echo command fails (which is unlikely to happen). With Docker, you can specify the command to run inside the container on the command line. But what if you want to run multiple commands? You can t escape the && syntax, or wrap the command in quotes, as Docker won t recognise it. The trick here is to usesh -c ' command1 && command2 [&& command3 [...]] 'For example, to run date and whoami in a vanilla ubuntu container, we would run the following:$ docker run ubuntu:latest sh -c 'date && whoami'Wed Feb 18 00:42:53 UTC 2015rootThis works because sh -c ' date && whoami ' is one call; the commands will be split and executed from within sh. The ls command will list files and directories in the current directory. But what if you only want to list the directories? There are a few ways to do this. One of the easiest ways is this:ls -d */The -d flag instructs ls to display directories instead of displaying directory contents. The */ instructs ls to perform the listing on subdirectories only. The output will look something like this:$ ls -d */hello_world/test_project/ Using Bash, there are a number of ways to test if a directory is empty. One of those ways is to use ls -A to list all files, including those starting with . and see if anything is printed. This can be done like so:if [ ! "$(ls -A path )" ]thenecho " path is empty!"elseecho " path is not empty"fiOr inline:if [ ! "$(ls -A path )" ]; then echo "empty!"; fiOr, for a slightly less readable version:test "$(ls -A path )" || echo "empty!"This works because test "" is true, and any other string value is false. If the directory is empty, ls -A will return an empty string. There are many ways in the linux terminal to print the nth word of a given file or output. One way to do this without worrying about tabs, extra spaces or word length is to use awk. With awk, this can be done on one line by using the {print $ n } syntax.For example, the ps command may print this:$ psPID TTYTIME CMD3677 pts/100:00:00 bash3699 pts/100:00:00 ps3700 pts/100:00:00 awkTo print only the fourth column (CMD), we can pipe the output to awk like so:$ ps | awk '{print $4}'CMDbashpsawk

TAGS:timmurphy org 

<<< Thank you for your visit >>>

Websites to related :
OtoRhinoLaryngology Portal | Drr

  OtoRhinoLaryngology Portal The Leading Online Gallery of Otolaryngology and Head & Neck Surgery Specialty This Website Focus Primarily on ENT Photos

The Grand at Diamond Beach Vacat

  You do not have Javascript enabled in your browser. Please update your browser settings to allow Javascript to see property images, descriptions, and

Keratosis Pilaris : The Chicken

  Home Keratosis Pilaris, KP, Chicken Skin March 2013Keratosis Pilaris HelpHelpForKP.com WHAT IS KP? - PICTURES - TREATMENTS - TIPS FAQ - KP FORUM - NEW

Art Miami

  The Art Miami Show Group has officially announced the cancellation of the 2020 editions of Art Miami | CONTEXT Art Miami | Aqua Art Miami due to conti

Fragrance Oils | Designer Fragra

  Dear loyal Fragrance Shop Customers,Our retail location in Carr Mill Mall is now open and we are following standard safety procedures.Please call 888-

Beamdog Forums

  Dark Dreams of Furiae - a new module for NWN:EE! Buy nowAttention, new and old users! Please read the new rules of conduct for the forums, and we hope

Proactive Training

  WE ARE PLEASED TO ANNOUNCE THATOur Sports Massage Diploma is now available online! This EXCLUSIVE ONLINE option to obtain our extended diploma will in

Aces and Eighths | A Resource Fo

  Aces and Eighths is a resource for musicians, beginners and professional alike, and a resource for music lovers. Our goal is to create a site that wil

Arelith Wiki

  Welcome to the Arelith Wiki! See the [Arelith Forum's wiki thread] and/or the Official Discord arelith-wiki-project to report errors, discuss changes

Recetas Con Ensaladas - Paso a P

  Receta ► Ensalada De Lentejas En RecetasConEnsaladas.com tenemos las mejores recetas de Ensaladas De Lentejas. Aquí encuentras las recetas de Read

ads

Hot Websites