INSTALLING THE LATEST LATEX
The simplest way is to download this file for Linux
http://mirror.ctan.org/systems/texlive/tlnet/install-tl-unx.tar.gz
Unzip, then run the install-tl file. This will do a network install of the latest version of latex.
http://www.tug.org/texlive/quickinstall.html
FLOAT FIGURES, APPROXIMATELY WHERE YOU WANT THEM
\usepackage{float}
\begin{figure}[H]
% figure stuff
\end{figure}
ADDING LINUX LIBERTINE FONT TO UBUNTU
http://sourceforge.net/projects/linuxlibertine/files/linuxlibertine/5.3.0/
CAN'T FIND pdflatex.fmt!
sudo fmtutil --all
http://ubuntuforums.org/showthread.php?t=1474358
INSTALL NEW TEX .CLS FILE FOR CV
Download LaTeX and LyX .zip files from this link.
Unzip the xetexCV.zip file, then copy the resulting LaTeX file xetexCV.cls to
~/texmf/tex/latex/local/, then run sudo texhash ~/texmf (in Ubuntu 12.10). Now unzip the xetexCV-LyX.zip file, and copy the xetexCV.layout file to /usr/share/lyx/layouts/
Open LyX, and then select Tools->Reconfigure. Restart LyX and there should now be a document style for curriculum vitae (xetexCV)
To get the compatible font (to avoid hacking xetexCV.cls), go to this link and this link, downloading Fontin and Fontin Sans fonts. Unzip the ensuing downloads, and copy the .ttf and .otf files to /usr/local/share/fonts by running sudo cp *.*tf /usr/local/share/fonts. Check that the fonts were installed correctly with fc-list | grep -i fontin . To view the file, simply go to View->Other Formats->PDF(XeTeX)
http://tex.stackexchange.com/questions/27659/how-to-use-downloaded-fonts-with-xetex-on-ubuntu
http://www.exljbris.com/fontin.html
http://tex.stackexchange.com/questions/1137/where-do-i-place-my-own-sty-files-to-make-them-available-to-all-my-tex-files
http://stefaanlippens.net/customLaTeXclassesinLyX
http://blog.oak-tree.us/index.php/2010/05/19/latex-cv-part4
http://blog.oak-tree.us/index.php/2009/11/25/latex-cv-part1
INSTALL KOMA SCRIPT
If you installed texlive-full it is already there! Add this to your .bashrc
export TEXINPUTS=.:/usr/share/texlive/texmf-dist/tex/latex/koma-script:
If you leave off the trailing colon bad things (like not searching the system directories!) happens
You may also need to add
\usepackage[english]{babel}
above
\begin{document}
in your .tex file
EXCELLENT TUTORIAL ON COVER LETTERS AND CV
http://stefano.italians.nl/archives/55
http://stefano.italians.nl/archives/50
SOME GREAT SHORTCUTS
http://wiki.lyx.org/Tips/FrequentlyUsedShortcuts
ADD A CV IMAGE
Using the CV(xetex) document, one can add
\cvimage{<FULL PATH TO IMAGE>}
to the LaTeX preamble (Document->Settings->LaTeX Preamble)
ADVANCED TRICKS
http://www.youtube.com/watch?v=bUyQcG8eIwA
http://www.dedoimedo.com/computers/latex-lyx-tips-more.html
FONT PACKAGES MISSING
In Ubuntu, sudo apt-get install texlive-full will install basically every package, which will usually eliminate font package errors.
ADD MULTIPLE LINES TO CASES IN LYX
Pressing CTRL+Enter when using cases in LyX will add a new line.
http://superuser.com/questions/76829/using-the-cases-environment-in-lyx
GOOD VIDEO TUTORIALS
http://www.youtube.com/watch?v=sJpfyydhAzo
http://www.youtube.com/watch?v=HvhdLJ0C6pk&feature=watch&lr=1
USING \LARGE
\large
\Large
\LARGE
\huge
\HUGE
To do only part, do {\large my_text}, as typefaces apply to all following text
http://www.personal.ceu.hu/tex/typeface.htm
http://tex.stackexchange.com/questions/7312/how-to-use-large-and-its-variants
COMMON MATH SYMBOLS
\, is a small space
\: is a medium space
\; is a large space
\approx is $\approx$
\equiv is $\equiv$
\sim is $\sim$
\sum\limits_{i=1}^n is $\sum\limits_{i=1}^n$
\cdots is $\cdots$
\ddots is $\ddots$
\ldots is $\ldots$
\vdots is $\vdots$
\mathcal{N} is $\mathcal{N}$
\left and \right are $\left|and \right|$
To do only one bar, do \left or \right in a \left \right pair on a period i.e.
\left. \right is $\left. \right|$
http://tex.stackexchange.com/questions/6969/symbol-for-gaussian-distribution
http://everythingyouforgetaboutlatex.blogspot.com/2008/11/another-quick-post-this-time-about-math.html
http://www.personal.ceu.hu/tex/symbols.htm
http://www-users.york.ac.uk/~pjh503/LaTeX/equations.html
http://www.personal.ceu.hu/tex/symbols.htm
http://en.wikibooks.org/wiki/LaTeX/Mathematics#Brackets.2C_braces_and_delimiters
CODE SNIPPETS
Adding code snippets
http://tex.stackexchange.com/questions/28554/is-there-a-way-to-enable-syntax-highlighting-coloring-in-lyx-for-program-listing
Monday, February 4, 2013
Tuesday, January 8, 2013
Polyphase Filters and Filterbanks
THIS BLOG HAS MOVED!
Don't worry - the code can still be found at:
https://github.com/kastnerkyle/Sandbox/tree/master/dsp/ under filterbank.py
Thursday, January 3, 2013
Connecting to Checkpoint/using SNX in Ubuntu 12.10 64bit
GET CONNECTED, NOT INFECTED
Get snx, either by going to your Checkpoint site, clicking Manual Download for Linux, and running the bash script downloaded, or by going to the Checkpoint website listed under Links and following the instructions there.
To get snx working properly, we will need to install some prerequisites by doing:
sudo apt-get install icedtea-7-plugin openjdk-7-jre ia32-libs libpam0g:i386
To connect to your Checkpoint site, run
snx -s <your_checkpoint_server> -u <username>, where <your_checkpoint_server> is the IP (i.e. 192.192.192.66) or DNS name (i.e. checkpointserver.example.org) of the Checkpoint server, and <username> is your domain login.
Once connected, you should be able to type ifconfig, and see a new interface called tunsnx with your VPN IP. You will probably need to remember the IP of at least one computer on the other side of the VPN in order to SSH - your company/school/whatever DNS probably won't resolve to right IP when you connect over VPN. I usually ssh to a "homebase" computer on the other side of the VPN, then ssh to other places as needed.
ssh me@192.192.192.67 - YES ----> ssh me@myworkserver - YES
ssh me@myworkdestop - DOUBTFUL
To disconnect, simply dosudo ifconfig tunsnx down; sudo pkill snx
For better disconnection, use snx -d ,as mentioned by kholis in the comments - thanks!
LINKS
https://supportcenter.checkpoint.com/supportcenter/portal?eventSubmit_doGoviewsolutiondetails=&solutionid=sk65210
http://kenfallon.com/check-point-ssl-network-extender/
Get snx, either by going to your Checkpoint site, clicking Manual Download for Linux, and running the bash script downloaded, or by going to the Checkpoint website listed under Links and following the instructions there.
To get snx working properly, we will need to install some prerequisites by doing:
sudo apt-get install icedtea-7-plugin openjdk-7-jre ia32-libs libpam0g:i386
To connect to your Checkpoint site, run
snx -s <your_checkpoint_server> -u <username>, where <your_checkpoint_server> is the IP (i.e. 192.192.192.66) or DNS name (i.e. checkpointserver.example.org) of the Checkpoint server, and <username> is your domain login.
Once connected, you should be able to type ifconfig, and see a new interface called tunsnx with your VPN IP. You will probably need to remember the IP of at least one computer on the other side of the VPN in order to SSH - your company/school/whatever DNS probably won't resolve to right IP when you connect over VPN. I usually ssh to a "homebase" computer on the other side of the VPN, then ssh to other places as needed.
ssh me@192.192.192.67 - YES ----> ssh me@myworkserver - YES
ssh me@myworkdestop - DOUBTFUL
To disconnect, simply do
For better disconnection, use snx -d ,as mentioned by kholis in the comments - thanks!
LINKS
https://supportcenter.checkpoint.com/supportcenter/portal?eventSubmit_doGoviewsolutiondetails=&solutionid=sk65210
http://kenfallon.com/check-point-ssl-network-extender/
Wednesday, November 21, 2012
Loading Ubuntu 12.10 on a Macbook Air
INSTALLATION
To create a live USB for installation, I had to follow the instructions at the link below. The basic steps were to convert the .iso to a .img using diskutils, then dd that image onto a USB driver, which was formatted as FAT_32 in my case. I think other formatting schemes may work as well.
Update: Trying to do this from non-Mac platforms, one can try
mkfs.hfsplus to create a .dmg file. To do this, you will need to install the hfsplus hfsprogs and hfsutils packages. you can then install dmg2img to convert this to .img format by installing dmg2img.
The whole command is sudo apt-get install hfsplus hfsprogs hfsutils dmg2img
See http://stackoverflow.com/questions/286419/how-to-build-a-dmg-mac-os-x-file-on-a-non-mac-platform for more details
Create a blank file of the size needed
dd if=/dev/zero of=/path/to/output.dmg bs=1 count=0 seek=590M
To create a live USB for installation, I had to follow the instructions at the link below. The basic steps were to convert the .iso to a .img using diskutils, then dd that image onto a USB driver, which was formatted as FAT_32 in my case. I think other formatting schemes may work as well.
Update: Trying to do this from non-Mac platforms, one can try
mkfs.hfsplus to create a .dmg file. To do this, you will need to install the hfsplus hfsprogs and hfsutils packages. you can then install dmg2img to convert this to .img format by installing dmg2img.
The whole command is sudo apt-get install hfsplus hfsprogs hfsutils dmg2img
See http://stackoverflow.com/questions/286419/how-to-build-a-dmg-mac-os-x-file-on-a-non-mac-platform for more details
Create a blank file of the size needed
dd if=/dev/zero of=/path/to/output.dmg bs=1 count=0 seek=590M
mkfs.hfsplus -v 'Description of DMG file' output.dmg
mount it, copy all files from ISO to DMG, then unmount.http://www.garrettcpa.net/dokuwiki/doku.php?id=linux:dmg
https://help.ubuntu.com/community/How%20to%20install%20Ubuntu%20on%20MacBook%20using%20USB%20Stick
Once the live USB is created, simply reboot the Macbook Air while holding the alt (option) key, then select the yellow USB UEFI icon as the boot device. Make sure to install 3rd party sources when running the installer, as the Broadcom wireless device uses a 3rd party firmware blob.
After running the Ubuntu installer, everything should be running, but there are still a few usability issues to fix. I will cover these issues under separate headings below.
XMONAD
Installing XMonad is the next crucial step for me - I don't install a wireless manager, doing wifi management with wpa_supplicant instead.
sudo apt-get install xmonad xmobar suckless-tools
Suckless-tools is a package of helpful tools for xmonad, such as dmenu. I use dmenu for launching graphical programs like firefox or
I have two example configs for a MacBook Air running XUbuntu 12.04, located at http://www.github.com/kastnerkyle/Configs .Simply put the ~.xmobarrc file at ~/.xmobarrc, and put the xmonad.hs file in ~/.xmonad/xmonad.hs
http://www.haskell.org/haskellwiki/Xmonad/Config_archive/John_Goerzen%27s_Configuration
WIRELESS
Wireless in XMonad is ...interesting. Here I will document some common wireless connectivity scenarios, and how get on the net.
Easiest - install trayer by doing sudo apt-get install trayer
Now simply do
trayer &
then
nm-applet
to start the network manager applet in the bottom left hand corner. Simply click and connect as normal. When finished, kill trayer by doing pkill trayer
http://ubuntuforums.org/showthread.php?t=843341
TOUCHPAD
After installing Ubuntu 12.10 and configuring XMonad, things appeared pretty good. The only issue so far is that the "right click" of the mousepad is two finger click, instead of clicking in the bottom right hand corner of the touchpad.
http://ubuntuforums.org/archive/index.php/t-1966016.html
https://help.ubuntu.com/community/How%20to%20install%20Ubuntu%20on%20MacBook%20using%20USB%20Stick
Once the live USB is created, simply reboot the Macbook Air while holding the alt (option) key, then select the yellow USB UEFI icon as the boot device. Make sure to install 3rd party sources when running the installer, as the Broadcom wireless device uses a 3rd party firmware blob.
After running the Ubuntu installer, everything should be running, but there are still a few usability issues to fix. I will cover these issues under separate headings below.
XMONAD
Installing XMonad is the next crucial step for me - I don't install a wireless manager, doing wifi management with wpa_supplicant instead.
sudo apt-get install xmonad xmobar suckless-tools
Suckless-tools is a package of helpful tools for xmonad, such as dmenu. I use dmenu for launching graphical programs like firefox or
I have two example configs for a MacBook Air running XUbuntu 12.04, located at http://www.github.com/kastnerkyle/Configs .Simply put the ~.xmobarrc file at ~/.xmobarrc, and put the xmonad.hs file in ~/.xmonad/xmonad.hs
http://www.haskell.org/haskellwiki/Xmonad/Config_archive/John_Goerzen%27s_Configuration
WIRELESS
Wireless in XMonad is ...interesting. Here I will document some common wireless connectivity scenarios, and how get on the net.
Easiest - install trayer by doing sudo apt-get install trayer
Now simply do
trayer &
then
nm-applet
to start the network manager applet in the bottom left hand corner. Simply click and connect as normal. When finished, kill trayer by doing pkill trayer
http://ubuntuforums.org/showthread.php?t=843341
TOUCHPAD
After installing Ubuntu 12.10 and configuring XMonad, things appeared pretty good. The only issue so far is that the "right click" of the mousepad is two finger click, instead of clicking in the bottom right hand corner of the touchpad.
http://ubuntuforums.org/archive/index.php/t-1966016.html
Tuesday, November 20, 2012
Using the Symmetricom bc635PCIe card as an NTP timesource
INTRODUCTION
NTP timeservers are a crucial part of any large-scale, distributed system, especially if the components of the system are spread across multiple sites. There are many commercial and homebrew options for setting up an NTP timesource. Some are fairly simple to set up, and others (like the Symmetricom bc635 PCIe card) require a little more work.I have recently set up an NTP server using the aforementioned card, and after all my troubles to get it set up, I decided to document the procedures used in this blog post.
PROBLEM
SETUP
Download the latest ntp source from http://www.ntp.org/downloads.html .For this tutorial, I used version 4.2.6p5
STEPS
There is a PDF from Symmetricom support that outlines most of the steps necessary to fix the driver. This list is largely a copy of their "how-to". However, I have elaborated on a few of the steps where I had issues.
- Install the bc635/637 driver. To do this, either run make install OR cp the windrvr6.ko and windrvr6_usb.ko files into the /lib/modules/drivers/ area, then do a depmod -a. There is a script called wdreg that will load up the driver, wdreg windrvr6. I added a call to the wdreg script in /etc/rc.local in order to get the module loading on boot, one could also add a rule to /etc/modules.conf.
- To verify, run the bc63xPCIcfg file that comes with the driver, from the sample/ folder.
- After rebooting the computer, the sample program should still work.
- Copy the libbcsdk.so file from the sample/ folder to /usr/lib/ (or another library directory of your choice).
- Make a link to the device driver, ln -s /dev/windrvr6 /dev/btfp0 (btfp0 is the old /dev file that ntpd looks for)
- If you haven't already done so, download the ntpd source code from www.ntp.org/downloads.html
- I used the ntp-4.6.2p5 source for this, but the 4.2.6p2 source has been used by others
- Extract the source, then modify the Makefile.in file in the ntpd/ folder. Find the segment that has ntpd_LDADD = $(LDADD) $(LIBOPTS_LDADD) ../libntp/libntp.a -lm @LCRYPTO@ @LSCF@, and add -lbcsdk
- Run this command in the ntpd/ directory - ./configure --enable-BANCOMM --enable-linuxcaps
- Look at the Makefile (NOT Makefile.in). There should be a line like ntpd_LDADD = $(LDADD) $(LIBOPTS_LDADD) ../libntp/libntp.a -lm -lbcsdk If not, add the -lbcsdk here, but know that running ./configure again will overwrite this Makefile.
- Edit the refclock_bancomm.c file as follows
extern uint32_t __attribute__ ((weak)) bcReadBinTimeEx(SYMMT_PCI_HANDLE, uint64_t *, uint64_t*, uint32_t*, uint8_t*);
At line 440
case 2: /* Linux/Windows, PCI, 2 32bit time words */
{
struct tm temp;
uint64_t btm[2];
uint32_t nano;
uint8_t dmy;
if (bcReadBinTimeEx(stfp_handle, &btm[1], &btm[0], &nano, &dmy) == 0)
{
msyslog(LOG_ERR, "get_datumtime error: %m");
return(NULL);
}
temp = *gmtime((time_t *)&btm[1]);
time_vme->year = (unsigned short)temp.tm_year+1900;
time_vme->day = (unsigned short)temp.tm_yday+1;
time_vme->hr = (unsigned short)temp.tm_hour;
time_vme->mn = (unsigned short)temp.tm_min;
time_vme->sec = (unsigned short)temp.tm_sec;
time_vme->frac = (btm[0] & 0x000FFFFF) * 1000;
time_vme->frac += (nano & 0x0000000F) * 100;
time_vme->status = (unsigned short)dmy;
#ifdef DEBUG
if(debug)
{
printf("Epoch time read from the BANCOMM card -> %ld\n", btm[1]);
printf("Decimal time read from the BANCOMM card -> Day:%d Year:%d H%02d:M%02d:S%02d.%06lu%d Status:%d\n",
temp.tm_yday+1,
temp.tm_year+1900,
temp.tm_hour,
temp.tm_min,
temp.tm_sec,
btm[0],
nano,
dmy);
printf("Decimal time read into time_vme -> Day:%hu Year:%hu H%hu:M%hu:S%hu.%lu Status:%hu\n",
time_vme->day,
time_vme->year,
time_vme->hr,
time_vme->mn,
time_vme->sec,
time_vme->frac,
time_vme->status);
}
#endif
//tvme_fill(time_vme, btm);
}
break;
One can remove all the commented lines, as well as the lines surrounded by
#ifdef DEBUG, but I have left them here for completeness.
Now run make. This should build a ntpd executable that will work with the libbcsdk.so library in order to read time from the Symmetricom PCIe GPS. If anyone knows how to handle the nanoseconds field, please let me know and I will update this post!
MODIFYING NTP.CONF
I then had to modify ntp.conf to use the device
# No restrictions on loopback
restrict 127.0.0.1
#Allow systems to sync
restrict 10.0.0.0 mask 255.0.0.0 nomodify notrap
restrict 192.168.0.0 mask 255.255.0.0 nomodify notrap
#Setup GPS PCIe Clock
restrict 127.127.0.0 mask 255.255.0.0
server 127.127.16.0 prefer mode 2 iburst minpoll 4 maxpoll 4
#Local clock source
#server 127.127.1.0
#fudge 127.127.1.0 stratum 8
driftfile /var/lib/ntp/drift
authenticate no
Here the server 127.127.16.x is a special subnet which refers to the Symmetricom(or BANCOMM) hardware clock when ntpd is compiled to support this radio.
The mode keyword is specific to each hardware radio. For Symmetricom, I have been unable to find information on what this mode means, but for Meinberg
see http://www.meinbergglobal.com/english/info/ntp.htm
Assuming that Symmetricom has the same convention, this would mean it is using a time string to send the information.
iburst allows the computer to sync more quickly with GPS time.
minpoll and maxpoll specify a time in seconds to poll the timesource for
time.
INSTALLING
For CentOS 6.2, I had to replace the existing ntpd in /usr/sbin/ntpd with the custom built version.
I have also had problems with ntpd not starting on boot -
I had to manually add a call starting ntpd to /etc/rc.local even though chkconfig showed ntpd on. It seems that ntpd starts but crashes? To be continued as I explore the issue further.
CHECKING THAT IT WORKS
Running ntpq -p should show the GPS clock, and you should see the reach column increase as the computer syncs with the card. If you see things working, but then an x appears in front of the entry for the card, that means there is another ntpd source that disagrees time-wise.
I have seen this in the past, which worries me a little, as I am supposedly pulling time straight from GPS. Maybe there is a bug in my code - or maybe the other server was wrong? In any case, using the GPS card as the only time source works great and has greatly decreased the footprint of my system.
http://www.linuxquestions.org/questions/linux-networking-3/ntp-conf-need-settings-for-a-refclock-using-symmetricom-bc635pci-timing-card-787257/#post4471512
http://www.eecis.udel.edu/~mills/ntp/html/ntpd.html
http://www.eecis.udel.edu/~mills/ntp/html/debug.html
http://compgroups.net/comp.protocols.time.ntp/proprietary-hardware-clock-as-ntp-ref/168850
https://support.ntp.org/bugs/show_bug.cgi?id=1674
https://support.ntp.org/bugs/show_bug.cgi?format=multiple&id=786
Sunday, September 16, 2012
Programming the ATTiny25 with Ubuntu
SETUP
To get all of the libraries and packages necessary to put a basic program on your AVR chip, run the following command.
sudo apt-get install gcc-avr avrdude avr-libc
ATTiny25 is plugged into a 40 pin ZIF socket, which is wired for HVSP mode. See this video for ZIF socket installation instructions https://www.youtube.com/watch?v=yJo29VMXt90
Other programming modes for AVR chips include PP and ISP - see this [PDF] link for pin wiring in order to program various AVR chips.
FULL COMPILATION COMMANDS
avr-gcc -Os -o hello.elf -mmcu=avr25 hello.c
avr-objcopy -j .text -j.data -O ihex hello.elf hello.hex
sudo avrdude -p t25 -c dragon_hvsp -P usb -e -B10 -U flash:w:hello.hex
If wired for ISP or PP mode, you should replace dragon_hvsp in the last step with dragon_isp or dragon_pp .
If you see this error:
jtagmkII_close(): bad response to GO command: RSP_ILLEGAL_EMULATOR_MODE
This error is actually OK - apparently HVSP mode shouldn't respond to this command, but avrdude sends it in ALL programming modes - see this link
ADDITIONAL INFO
/etc/avrdude.conf has a lot of (specific) information about each supported chip.
MORE LINKS
http://www.instructables.com/id/Getting-started-with-ubuntu-and-the-AVR-dragon/
http://tldp.org/HOWTO/Avr-Microcontrollers-in-Linux-Howto/x207.html
http://www.nongnu.org/avr-libc/user-manual/using_avrprog.html
http://www.homebuilthardware.com/index.php/avr/linux-avrdragon-tutorial-1/
To get all of the libraries and packages necessary to put a basic program on your AVR chip, run the following command.
sudo apt-get install gcc-avr avrdude avr-libc
ATTiny25 is plugged into a 40 pin ZIF socket, which is wired for HVSP mode. See this video for ZIF socket installation instructions https://www.youtube.com/watch?v=yJo29VMXt90
Other programming modes for AVR chips include PP and ISP - see this [PDF] link for pin wiring in order to program various AVR chips.
FULL COMPILATION COMMANDS
avr-gcc -Os -o hello.elf -mmcu=avr25 hello.c
avr-objcopy -j .text -j.data -O ihex hello.elf hello.hex
sudo avrdude -p t25 -c dragon_hvsp -P usb -e -B10 -U flash:w:hello.hex
If wired for ISP or PP mode, you should replace dragon_hvsp in the last step with dragon_isp or dragon_pp .
If you see this error:
jtagmkII_close(): bad response to GO command: RSP_ILLEGAL_EMULATOR_MODE
This error is actually OK - apparently HVSP mode shouldn't respond to this command, but avrdude sends it in ALL programming modes - see this link
ADDITIONAL INFO
/etc/avrdude.conf has a lot of (specific) information about each supported chip.
MORE LINKS
http://www.instructables.com/id/Getting-started-with-ubuntu-and-the-AVR-dragon/
http://tldp.org/HOWTO/Avr-Microcontrollers-in-Linux-Howto/x207.html
http://www.nongnu.org/avr-libc/user-manual/using_avrprog.html
http://www.homebuilthardware.com/index.php/avr/linux-avrdragon-tutorial-1/
Thursday, September 13, 2012
Writing better C/C++ code
ENABLING LINK -TIME OPTIMIZATION
-flto
https://stackoverflow.com/questions/20977741/stdvector-performance-regression-when-enabling-c11?noredirect=1#20977741
RESOURCES ON FUNCTION POINTERS
http://denniskubes.com/2013/03/22/basics-of-function-pointers-in-c/

http://milotshala.wordpress.com/2012/02/21/virtual-functions-in-c/
To compile Qt related code with g++ (on Ubuntu 11.10+)
g++ -I /usr/include/qt4 -I /usr/include/qt4/QtCore -l QtCore test.cpp test.h -o test.test
qmake -project
Then fill in the resulting .pro file - much easier
C/C++
_Generic macros... awesome
http://www.robertgamble.net/2012/01/c11-generic-selections.html
http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1404.htm
Set a single function to be called any time exit() is run
http://www.codecogs.com/reference/computing/c/stdlib.h/atexit.php
Ensuing discussion with good error checking macros
http://www.reddit.com/r/programming/comments/1856qx/how_did_i_miss_this_feature_in_c_so_far/
Excellent list of good compile time options
http://stackoverflow.com/questions/3375697/useful-gcc-flags-for-c
Example of parsing commandline arguments for C or C++ code
-flto
https://stackoverflow.com/questions/20977741/stdvector-performance-regression-when-enabling-c11?noredirect=1#20977741
RESOURCES ON FUNCTION POINTERS
http://denniskubes.com/2013/03/22/basics-of-function-pointers-in-c/

QT// forward declaration of our struct before it's definitionstructClassA;// The actual function table that holds function pointers.typedefstruct{void(*ClassA)(structClassA*);// the "constructor"void(*set)(structClassA*);// set functionint(*get)(structClassA*);// get function} ClassA_functiontable;typedefstructClassA {intdata;ClassA_functiontable *vtable;// ClassA virtual method table} ClassA;// ClassA's function prototypes (forward declarations)voidClassA_constructor(ClassA *this);voidClassA_set(ClassA *this);intClassA_get(ClassA *this);// Static array of the function table struct that contains ClassA's functions.ClassA_functiontable ClassA_vtable = {ClassA_constructor,ClassA_set,ClassA_get };// Implementation of functions and the constructor.voidClassA_constructor(ClassA *this) {this->vtable = &ClassA_vtable;this->data = 10;}voidClassA_set(ClassA *this) {printf("ClassA is increasing\n");this->data++;}intClassA_get(ClassA *this) {this->vtable->set(this);returnthis->data;}
To compile Qt related code with g++ (on Ubuntu 11.10+)
qmake -project
Then fill in the resulting .pro file - much easier
C/C++
_Generic macros... awesome
http://www.robertgamble.net/2012/01/c11-generic-selections.html
http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1404.htm
Set a single function to be called any time exit() is run
http://www.codecogs.com/reference/computing/c/stdlib.h/atexit.php
Ensuing discussion with good error checking macros
http://www.reddit.com/r/programming/comments/1856qx/how_did_i_miss_this_feature_in_c_so_far/
Excellent list of good compile time options
http://stackoverflow.com/questions/3375697/useful-gcc-flags-for-c
Example of parsing commandline arguments for C or C++ code
void ShowUsageAndExit()
{
{
float VERSION=1.0;
printf("Special sample code v%f\n",VERSION);
printf("Usage: specsamp [options]\n");
printf("\t -h .......... prints this help\n");
exit(0)
}
int main(int argc, char** argv)
{
{
int arg=1;
while(arg<argc) {
if(argv[arg][0] != '-') {
show_usage_and_exit();
}
switch(argv[arg++][1])
{
case 'h':
ShowUsageAndExit();
break;
default:
ShowUsageAndExit();
break;
}
}A quick sample of how to write C modules that will compile fine with a C++ compiler as well. For header file named test.h, something like this would be expected:
#ifndef _TEST_H_
#define _TEST_H_
#ifdef __cplusplus
extern "C" {
#endif
INCLUDES
extern "C" {
#endif
INCLUDES
CODE
CODE
#ifdef __cplusplus
}
#endif
#endif //_TEST_H_
Use a function like this to safely malloc:
void* SafeMalloc(size_t sz)
{
void *m = malloc(sz);
if(!m)
{
fprintf(stderr, "Malloc failed for size %zd\n", sz);
exit(1);
}
return m;
}
For passing fields to subfunctions, malloc() and free() is the way to go (or new and delete if using C++ != C++11)
GPGPU/CUDA
Avoiding branching for GPGPU, instead of:
if(cond(i))
{ out[i] = f(i); }
else
{ out[i] = g(i); }
Use this:
out[i] = f[i ] + cond[i] *(g[i]-f[i])
You compute everything - just as in the "standard" pattern - and you have another multiply-and-add, but you have only one commit to memory. It's sometimes better even in nested conditions.
(Not my words, originally commented by David on this post)
DEBUGGING TECHNIQUES
(gdb) define xxd
>dump binary memory dump.bin \$arg0 \$arg0+\$arg1
>shell xxd dump.bin
>end
(gdb) xxd &main 10
0000000: 0000 0000 0000 0000 0000 0000 4d8c a7f7 ............M...
0000010: ff7f 0000 0000 0000 0000 0000 c8d7 ffff ................
0000020: ff7f 0000 0000 0000
Subscribe to:
Comments (Atom)