I do a lot of typesetting, and a lot of my work in vim which means that I do a lot of compiling and displaying latex. Normally, I would either use a multiplexer like Screen or Tmux (I actually prefer Screen) to switch back and forth between the source code and compiling; plain old quitting vim to compile; or compiling within vim using something external commands. Although all of them work, they take a lot of keystrokes and are a hassle, and when you have to compile hundreds of times a day, the time adds up. So let's make it better!
What I want
I want either a command or a key map that will compile my current file and display it.
How I did it
By creating a custom command that compiles the current document using pdflatex, displays it using evince (or your favorite pdf viewer), makes sure that all the output is piped to /dev/null, and then redraws the screen. This will create a user-defined command,
:Latex, that will compile and display your document.
command Latex execute "silent !pdflatex % > /dev/null && evince %:r.pdf > /dev/null 2>&1 &" | redraw!
You want this to be in your
~/.vimrc so that it will autoload.
The first keyword
silent will prevent vim from displaying the "Press ENTER to continue" screen that is usually displayed whenever external commands are executed.
The first step uses pdlatex to compile the current file, denoted by
% and pipes standrard output to
The second step uses a logical
&& so that the command will short-circuit if compilation failed, and then uses evince (or your favorite pdf viewer) to open the file. Note that we use
%:r to get just the filename of the current document and then append
.pdf to get the compiled version. Again we
/dev/null and additionally pipe
stdout to prevent errors from getting displayed. The command ends with a bitwise
& so that the pdf viewer runs in the background
Finally the bitwise
| is used to execute multiple commands, after which we redraw the screen. This is necessary to prevent artifacts from showing in the buffer.
Adding a key map (Optional)
:Latex every time you want to compile is also too much, you can additionally map a key to execute it for you.
:map <F2> :Latex <CR>
This will map F2 to execute the Latex command ( is for carriage return, equivalent of pressing ENTER)
More VIM configuration
My entire vim configuration file (along with other common dotfiles) is on GitHub.
I recently redid my personal website and ended up deploying it to both my personal domain and my UT website. In order to facilitate development and deployment I set up Git post-receive hooks on my servers so I could update my website with one command:
git push web. This post will explain how you can do the same.
Setting up git locally
The first step is to git track the local copy of your website (only required if you haven't already initialized git on the local copy)
Using your favorite shell, navigate to the local copy of website on your computer and start git
git add .
git commit -a -m "First commit!"
You have now initialized git, tracked your files, and committed your work!
Setting up git on server
Assuming you have a web server that you can ssh into we can the proceed on the server
git init --bare
This will create a folder and initialize a barebones git repository within.
We then create a post-receive hook that will be called whenever you deploy and will update the latest version of your website
Then use your favorite text editor (vim, emacs, nano, etc...) to create 'post-receive' that will contain the following:
GIT_WORK_TREE=~/public_html/ git checkout -f
chmod -f -R o+x ~/public_html
The first line specifies that this is bash executable
The second line sets the GIT_WORK_TREE environment variable to wherever your public html files are located (usually in /var/www or ~/public_html)
The third line is optional, it gives the "others" group permission to execute files. This is a failsafe to ensure that apache can execute .php files.
In order to activate this hook, we must make it executable
chmod +x post-receive
Pushing to server
Returning to the local copy of the website
git remote add web username@yourserver:~/deploy.git
git push web +master:refs/heads/master
Deploying to your website is now a breeze! Your typical development workflow will be
- Edit files like you normally would
git add . (if you create new files)
git commit -a -m "your message" to commit your changes
git push web to deploy!
- Rinse and repeat
This year I attended my first hackathon, UT's very own: HackTX. It was an extremely exciting event, filled with smart people, cool companies, even cooler projects, and free swag!
I entered the competition with my friend, Will Yager, who specializes in embedded systems and cryptography. We decided to create a web service to cryptrographically timestamp data. My task was to create the web front-end and the back-end server to handle requests, files, and payments. Will had to create the bitcoin server which provides an API to timestamp and verify files and data.
We used $300 that RackSpace gave us in credit to rent a high-speed server where we ran a LAMP stack and a python bitcoin wallet and web server.
We used Apache and PHP to server the webpages as well as handle the file or data uploads. The data is then hashed using SHA256 and passed on (as a hash) to the python which creates a bitcoin transaction containing the hash in the message. Once the transaction committed to the blockchain (verified by the bitcoin network), it becomes permanent, and can therefore be securely used to prove existence.
Although ProveMe is not necessary to prove the existence of the data, ProveMe provides a way to upload data and check if it has been timestamped on the blockchain, and if it has, to see when.
Although we did not win, we still had an amazing time hacking and meeting awesome people!
PS: Our servers are no longer online, you can check out the project on HackerLeague, and the source code for the bitcoin server on GitHub
PPS: If you are actually interested in this service, a similar service (which came out after ProveMe) is Proof of Existence
As a regular AirDroid user, I found that there is only thing keeping AirDroid from perfection: true message notifications. If you happen to be away from your phone (or have it on silent) and receive a message, the only notification you get is a small toast within the web interface; no sound, and no persistant notification. This means that I often have to be checking the Airdroid tab for new messages. After some researching, I could not find any simple solution for my problem; so I created my own.
I present: AirDroid Notifier!
This is a simple, lightweight Google Chrome extension that will notify and ring you whenever you receive a new message!
It uses webkit notification to ensure that you see it regardless of what window/tab you are using. Any incoming text message will trigger a notification that can be seen from any tab, any window, or any application.
This extension is 100% free and simple to use! Just install it and get notified!
View in Chrome Web Store
Disclaimer: This extension and its author, are not affiliated with, endorsed, or sponsored by AirDroid
*The AirDroid icon and name are trademarks of Sand Studio
Finally, my Google Chromecast arrived in the mail! It came in a tightly packed and simple box that somewhat resembled the packaging using by Apple in the pre-transparent-plastic cases. Inside the box was the actual Chromecast, a usb to micro-usb cable with a velcro cable wrapper, an AC adapter, and a little instruction booklet.
Set-up was a breeze. Literally a 3 step process:
- Connect Chromecast to TV (and to power if you don't have HDMI >1.4)
- Download Chromecast app and connect
- Use either Google Chrome (PC or Mac) or any of the available iOS/Android apps to cast your content!
I am very happy with my chromecast! Although casting tabs is intensive on the host computer and the quality is limited to 720p, watching YouTube videos in 1080p seems to work well!
Although the number of compatible apps is relatively low right now, once Google gives 3rd party developers the go to release their apps I am sure that there will be plenty of innovative uses for this amazing piece of technology!
And honestly for such a low price $35, its a great addition to any home entertainment system!
As my first RaspberryPi Project I decided to build a clock using the two LED dot matrices I bought. In addition to providing a quick glance at the time I wanted to be able to quickly tell if I had any new unread emails. Thus the emClock* was conceived!
My first goal was to build the clock!
The two LED dot matrices I bought came with an I2C compatible interface which made set up and programming infinitely times easier than having to solder and multiplex 64 LEDs by myself.
Enabling I2C on the RPI is a breeze as there are many great tutorials out there for how to do it. To access them programmatically them I used Adafruit's LED Backpack python library.
After setting up the LED matrices I had to create a framework for displaying numbers. I created a an array of matrices which represent the LED's that are powered for each number. For example number zero is defined as:
n0 = [[1,1,1],
This allowed me to write a generic plotNumber function which takes two parameters: which number to display, and where to display it
wgrid = grid
wgrid = grid2
for ix, x in enumerate(nums[n]):
for iy, y in enumerate(x):
Once I created a framework for displaying the numbers, building the actual time-keeping function was easy.
pastMinute = 0
now = datetime.datetime.now()
hour = now.hour
minute = now.minute
second = now.second
if minute != pastMinute:
pastMinute = minute
In order to keep time, I create a thread which runs
clockStep() every second using a threading helper function from StackOverflow
def do_every(interval, worker_func, iterations = 0):
if iterations != 1:
do_every, [interval, worker_func, 0 if iterations == 0 else iterations-1]
Once the clock portion was done, it was time to add the email checking functionality! Now, I am a Google fanboy so naturally I used Gmail, which conveniently provides an RSS feed for your emails which can be accessed at https://USERNAME:PASSWORD@mail.google.com/gmail/feed/atom.
Armed with this knowledge, we can proceed to write our emailCheck() function!
pastEmails = 0
emails = newmails = int(feedparser.parse("https://EMAIL:USERNAME@mail.google.com/gmail/feed/atom")["feed"]["fullcount"])
if emails > pastEmails:
pastEmails = emails
elif emails < 2:
We can invoke emailCheck() and clockStep() using our threading helper function
And thus emClock was born! :D
The full source code is available here
*My first idea for a name was Glock (Gmail + clock) but apparently some gun company beat me to it :P