nginx proxy_pass based on domain

Nginx supports multiple server blocks listening on the same port; this is how Virtual Hosts work; thus we simply proxy_pass virtual hosts to our desired target.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
server {
listen 80;
server_name soundcloud.com;
location / {
proxy_pass http://soundcloud.com;
}
}
server {
listen 80;
server_name api.soundcloud.com;
location / {
proxy_pass http://api.soundcloud.com;
}
}

https://stackoverflow.com/questions/21064401/route-different-proxy-based-on-subdomain-request-in-nginx

Moving House

Previously I had this blog hosted on RedHat’s OpenShift PaaS using WordPress. I haven’t been blogging frequently for about 2 years, and I missed RedHat’s memo about the migration because I registered using an obscure email from a shell account without webmail. https://blog.openshift.com/migrate-to-v3-v2-eol/ Lo and behold my blog has vanished, although thankfully I have the entire SQL dump (and most of the crucial media) from the beginning of this year. To minimize the chance of this happening ever again (and to minimize the effort of getting my site up and running again, knock on wood) SSGs seem like the best solution since they have the content in a portable, versionable format, although I would have preferred a Ghost blog.

Hexo caught my eye over other static site generators due to:

  • Complete compatibility with Octopress plugins
  • hexo server -d watches the filesystem and automatically generates new content upon reload
  • Prebuilt themes like the one I’m using now have the basics of what a nerdy blog needs OOTB:
    • $\textbf{MathJax}$
    • Instant support with an npm install hexo-tag-fontawesome
    • SEO basics like a configurable sitemap and newfangled generator plugins for stuff like Google AMP which will close the gap between CMSes
  • One line deploy to Git, (S)FTP, among other targets

nVidia CUDA samples on Ubuntu 16.04 LTS

Here they are in case anyone else needs to download them separately (and the rest of cuda-repo-ubuntu1504-7-5-local_7.5-18_amd64.deb):

https://drive.google.com/open?id=0B_SnrcTvZzIXX2dkM0pwT2E3U2s
https://mega.nz/#F!dVBghK7J!6nvh-XvvoiqqeGp144jouw

The file you’re looking for is var/cuda-repo-7-5-local/cuda-samples-7-5_7.5-18_amd64.deb

To extract and compile the samples (make sure you have your nVidia GPU active if you’re using Optimus, e.g. by using

sudo prime-switch nvidia

or otherwise;

nvidia-smi

should show your GPU’s details.

1
2
3
4
ar x cuda-samples-7-5_7.5-18_amd64.deb
tar -xf data.tar.gz
cd /usr/local/cuda-7.5/samples/5_Simulations/smokeParticles/
CUDA_PATH=/usr CUDA_SEARCH_PATH=/usr/lib/x86_64-linux-gnu/ make -j5

First Foray into MIPS Assembly

Task: Print Hello World 10 times.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
.data
hello_str: .asciiz "Hello World!n"
.text
.globl main
main:
subu $sp, $sp, 4 # create a word on the stack
sw $ra, 4($sp) # store the return address
# put main function code here
li $t0, 10 #the number at which we want to end our loop.
li $t1, 0 #start counting from 0; we are going to increment this counter 10 times.
li $v0, 4 # set $v0 to print_string; http://courses.missouristate.edu/kenvollmar/mars/Help/SyscallHelp.html
la $a0, hello_str # load the string
loop:
beq $t1, $t0, end # if t1 == 10 we are done
syscall # execute the function described by
addi $t1, $t1, 1 # add 1 to t1
j loop # jump back to the top
end:
li $v0, 10
syscall

recorded_compressed

Concatenating FLV files with ffmpeg

First foray into Haskell.

Defining the combination formula (nCr) recursively.

1
2
3
4
5
Prelude> let ncr n k | k == 0 = 1 | n == k = 1 | otherwise = ncr (n-1) k + ncr (n-1) (k-1)
Prelude> ncr 3 2
3
Prelude> ncr 15 4
1365

This works because http://www.cs.nott.ac.uk/~vxc/g51mcs/ch05_combinatorics.pdf , page 9.

How to fix popping on audio start/stop/resume with Intel HDA audio in Linux

https://wiki.archlinux.org/index.php/Alsa#Pops_when_starting_and_stopping_playback My ears were nearly wrecked by this awfulness. On a side note, the Conexant Audio CX20751/2 isn’t the best integrated sound card around. Even lowly Realteks have far better dynamic range and equalization. There is virtually no soundstage, mids are very muffled, even with headphones. It can be found on some lower end Thinkpads (e.g. S440/E440); considering that these are cheap SMB laptops it’s not surprising that they had to cut corners somewhere.

Another alternative to checkinstall

Checkinstall didn’t work for me in CentOS 7 even after following this guide: http://www.patrickmin.com/linux/tip.php?name=checkinstall_fedora_13 and using –fstrans = no. Solution: https://github.com/jordansissel/fpm Using nginx 1.7.3 as an example:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
$ ./configure --sbin-path=/usr/local/sbin/nginx --with-http\_ssl\_module --prefix=/usr/local/nginx
$ make install DESTDIR = /tmp/nginxinstalldir && cd /tmp/nginxinstalldir
$ fpm -s dir -t rpm -n nginx -v 1.7.3 -d 'openssl-devel' -d 'openssl-libs' -d 'openssl' -d 'pcre' -d 'pcre-devel' -d 'zlib' -d 'zlib-devel' usr/
# rpm -qpR nginx-1.7.3-1.x86_64.rpm
openssl-devel
openssl-libs
openssl
pcre
pcre-devel
zlib
zlib-devel
rpmlib(PayloadFilesHavePrefix) <= 4.0-1
rpmlib(CompressedFileNames) <= 3.0.4-1
# rpm -ivh nginx-1.7.3-1.x86_64.rpm

Of course, this is by no means a substitute to properly packaging packages for upstream using rpm-build, but it is perfect for compiling from source quickly without having files strewn all over the place, especially when there is no make uninstall.

GNU Screen on Steroids

Note: This is an old post, from an old blog far, far away Append this to your ~/.bashrc:

1
2
3
case "$TERM" in
screen*) PROMPT_COMMAND='echo -ne "�33k�33�134"'
esac

and this to your .screenrc:

1
2
hardstatus alwayslastline '%{= G}\[ %{G}%H %{g}\]\[%= %{= w}%?%-Lw%?%{= R}%n*%f %t%?%{= R}(%u)%?%{= w}%+Lw%?%= %{= g}\]\[ %{y}Load: %l %{g}\]\[%{B}%Y-%m-%d %{W}%c:%s %{g}\]'
shelltitle '$ |bash'

Courtesy of http://superuser.com/questions/244299/gnu-screen-how-to-update-dynamically-the-title-of-a-window and http://beerpla.net/2009/10/06/supercharge-your-gnu-screen-with-a-power-taskbar-and-never-feel-lost-again/

If you want to keep your splits/panes persistent even when you detach: The short is answer is that you can’t. The longer answer is that you can fake it. (Note: the next screen release, probably numbered 4.1.0, will be able to remember display layouts.) Splits are a property of your display. The process managing your screen session doesn’t really know about them; only the single process that’s displaying the session does. Thus, the screen session can’t remember the splits because it doesn’t know about them, and once you detach, the process that did know about them has exited. The hack is to use nested screen sessions. Start one session and give it some escape sequence that you won’t use much (or just disable its escape character completely). Bind your usual detach key sequence to this screen session. Now, start or attach to your main screen session. All of your work will be done in the inner session, and you can split your display. When you detach, however, it will be the outer session that detaches, so your splits in the inner session will be preserved.

http://aperiodic.net/screen/faq#when_i_split_the_display_and_then_detach_screen_forgets_the_split

Your browser is out-of-date!

Update your browser to view this website correctly. Update my browser now

×