21.2.23

MacBook Air 2020 SMC PRAM reset

MacBook Air 2020, unresponsive if monitor is closed and reopened. MacBook Air 2020, charger not recognized after monitor is closed and reopened.

SMC Reset:  Plug in charger.  Press right shift, left control, left option keys for 7 sec, then press power key. Hold all four keys for 7 more seconds.  Machine -may- restart on its own after a period of time.

PRAM Reset:  Hold option, command, P, and R for 20 seconds until second chime or Apple logo appears and disappears a second time.

13.11.20

PLINK STRUCTURE output to NTSYS PCOMC input

#create input for NTSYS/PCOMC from *strct_in files
f="ApolloLeafCASDENfbpQ30snp.str0505.recode.strct_in"; # STRUCTURE output file from PLINK

ncl=$(head -1 "$f" | awk -F' ' '{print NF}'); #calculate number of loci from 1st line of *strct_in
nrw=$(tail -n +3 "$f" | wc -l); #number of samples

#make the .ntb file
ntbfn="ALLCS"; #NTSYS input file name
echo "*simgend d=row c=band o="$ntbfn".nts r=Dist"$ntbfn".nts
*dcenter o=Dist"$ntbfn".nts  r=Dcent"$ntbfn".nts
*eigen o=Dcent"$ntbfn".nts  n="$nrw" r=proj"$ntbfn".nts" > "$ntbfn".ntb;
unix2dos "$ntbfn".ntb;

#make the .nts file
#create header
r="1 "$nrw"B $(( $ncl * 2 ))L 1 -9"; #matrix description line
s=""; #locus description line
for i in $(seq 1 1 $ncl);
  do s+=$i"a "$i"b ";
  done;
header=$(echo "$r"; echo "$s" | sed 's/ $//');    

#create data matrix
labs=$(tail -n +3 "$f" | cut -d' ' -f1);
matx=$(tail -n +3 "$f" | cut -d' ' -f3- | sed 's/0/-9/g');
matxx=$(paste -d' ' <(echo "$labs") <(echo "$matx"));

echo "$header"$'\n'"$matxx" > "$ntbfn".nts; #assemble the .nts file
unix2dos "$ntbfn".nts;

4.3.20

Bash one-liner to calculate md5sum by line, using Python

python -c "exec(\"import hashlib, sys\nfor line in sys.stdin:\n\tprint hashlib.md5(line).hexdigest()\")" <<<123$'\n'456


Output (includes newline):
ba1f2511fc30423bdbb183fe33f3dd0f
d2d362cdc6579390f1c0617d74a7913d
 

28.2.19

Convert EMF file to PDF, PNG using ImageMagick

Install ImageMagick on a Windows machine.
magick infile.EMF outfile.pdf
magick infile.EMF outfile.png

29.11.18

Regex to extract citations and other parenthetical expressions from text

Print out parenthetical expressions using sed:
sed 's/(/\n(/g' InputFile.txt | sed 's/)/)\n/g' | grep "^(";

Remove parenthetical expressions using perl: 
perl -pe 's|(\(.*?\))||g' InputFile.txt;

26.11.18

Homebrew, Mac OS 10.11, Xcode 8, Clang, and the problem with thread_local

The version of the clang compiler that comes with Xcode 7 does not recognize the thread_local keyword.  Packages installed with Homebrew that use certain c++11 or higher commands may terminate during compilation with errors like "thread-local storage is not supported for the current target".  Xcode 8, which contains a suitable clang, cannot be run on MacOS 10.11.  Catch-22.

To work around, install a new version of gcc using Homebrew:

brew install gcc;

Now figure out which version of gcc was installed by Homebrew:

brew list gcc;

If gcc 8 was installed you will see something like: /usr/local/Cellar/gcc/8.2.0/bin/gcc-8
in the list of brew-installed gcc programs.  Now, tell Homebrew to use this newer version of gcc, instead of the old version of clang from xcode, to install your program.  As an example, I use the package poppler:

brew install --cc=gcc-8 poppler;