Switch between Playback Devices on Windows using a hotkey

August 9, 2014

I got my windows machine hooked up both to my work station, which means an LCD and regular speakers, and to my TV. When I play something on my TV, I want my sound to go through the HDMI and play from my TV speakers. Now, the way to do this is on most windows versions is to right click your speaker icon in the taskbar, choose Playback Devices, and mark your TV as the Default Playback Device. Vice versa when you want to switch back to your PC speakers.

This isn’t very comfortable if you’re sitting on your couch :)

AutoHotKey to the rescue!

What you wanna do is:

1) Install AutoHotKey (http://www.autohotkey.com/)

2) Open notepad, copy paste the following code into it and save it as an .ahk file:

ScrollLock::
toggle:=!toggle ;toggles up and down states.
Run, mmsys.cpl
WinWait,Sound ; Change “Sound” to the name of the window in your local language
if toggle
ControlSend,SysListView321,{Down 1} ; This number selects the matching audio device in the list, change it accordingly
Else
ControlSend,SysListView321,{Down 2} ; This number selects the matching audio device in the list, change it accordingly
ControlClick,&Set Default ; Change “&Set Default” to the name of the button in your local language
ControlClick,OK
return

(You’ll notice I used the ScrollLock key as the hotkey. You’re welcome to change it to whatever you like obviously)

3) Double click the .ahk file. This will enable it until your next restart (probably need to autorun it at startup for convenience. Never got around to doing it since I so rarely restart my machine).

4) Double click on ScrollLock and watch the magic happen :)

 

Enjoy!


The gentleman’s guide for building a deadmau5 head

March 10, 2012

Let me start off by saying that if this inspires you to make a deadmau5 head of your own, keep in mind that constructing it is only half the work. The other half would be crowd control when you wear it. Expect “some” love from the crowd. But more on that later.

So Purim was coming around the corner, and it’s been a while since I made a worthy costume. Purim is the Israeli equivalent of Halloween. You know, when girls are “allowed” to dress slutty, and for “some reason” we’re fine with that :-) . I decided I’ll make a deadmau5 head.

Sneak preview of the end result:

A quick Google search yields some great tutorials on how to make it, and I made good use of them. In the end,  I chose different ideas from different tutorials. First off you need the primary globe for the head. A whole different approach to making a mau5head is to use papier-mâché, but I think that yields a brittle result, and seeing that I don’t want to spend most of my time worrying about someone hitting my mau5head and putting a hole in it, I opted for the more durable acrylic approach. So I got my hands on one of those hamster balls, which wasn’t so easy in Israel. The biggest one I could find was 13″ in diameter, which is the bare minimum. I guess we aren’t that keen on big hamster balls over here.

In order to let my head come through, I had to cut one hole bigger. In retrospect, I did not cut it like I should have. I made the hole bigger by simply making a bigger circle, adjacent to the existing one.

Marking where to make the cut

That was eventually a problem, as my chin was too visible, ruining the effect. To counter it, I later “hacked” the helmet inside, but that came at a cost – comfortableness. Oh well, live and learn :-)

What I should have done is cut it askew, tilting the cut towards the back of the head. That would still allow my head to get inside, but would make the front look better. The back would be a bit more exposed, but obviously it’s less important than the front. So if you do make your own deadmau5 head – make sure to cut it the proper way (with the tilt).

Here is how I cut up the acrylic:

Safety first!

Safety first!

Dremel FTW!

Circumcised hemisphere

Next up – the mouth. I sketched out how to cut the mouth freehand, using the globe’s notches as reference points, to make sure I’m drawing an equal curve on both sides. I also had to make sure I leave enough plastic on the bottom, so it will have structural integrity later on (again, this would have been easier if I had tilted my first cut). By the way, the acrylic itself is very easy to cut. Luckily, I have a Dremel at home, and the acrylic cuts up nicely (doesn’t crack or anything like that). Here’s a short clip of me making the first cut:

Since I was going to wear the mau5head for several hours each time, it needed to be comfortable. So I bought a simple construction helmet, and bolted it to the inside of the upper hemisphere. I simply drilled two holes in the helmet and two holes in the acrylic, and connected them using two nuts and screws.

The ears: Before deciding on the material for the ears, I had to figure out how to attach them to the head so they won’t fall off easily (simply gluing them won’t cut it). Most tutorials propose the approach I eventually chose as well – inserting two metal rods into each ear, drilling two holes into the acrylic, and fastening them together with two butterfly nuts. Since I chose that approach, I also decided to use some sort of lightweight, porous plastic foam for the ears. I inserted the metal rods into each ear by heating them up and driving them inside the foam. A little silicon to hold it all together, and viola!

Metal rods inserted in to the ear

I gave the ear its bottom curve using a heated knife

Silicon reinforcement

Silicon reinforcement

Inserting the ears

Inserting the ears

Securing the helmet - view from above

Securing the helmet - view from above

Securing the helmet - view from inside

Securing the helmet - view from inside

A quick overview of how it all fitted together:

All those hours playing Lego are starting to pay off...

All those hours playing Lego as a child are starting to pay off...

The next part was my least favorite – covering it up with fabric. I won’t elaborate too much on that part, mostly since I find it to be highly frustrating (I hate working with fabric). I used felt cloth to cover the mau5head, covering the ears and hemispheres:

Covered hemisphere (top)

Covered hemisphere (top - front)

Covered hemisphere (top - rear) - ugly post-lobotomy look

Covered hemisphere (top - rear) - ugly post-lobotomy look

Covered ear

Covered ear

It was starting to take shape:

Covered top mau5head

Covered top mau5head

Looks like it’s missing some eyes… for the eyes I took two small plastic hemispheres, used strips of electrician’s tape to make a + (plus sign) pattern on them and spray painted them:

Pre-spray

Post-spray

Once I finish the eyes’ inner electronics, they would be hot glued to the mau5head.

Now came the fun part – wiring the electronics :-) I wanted the eyes to light up, so I drilled two holes in the upper hemisphere, where the eyes would roughly be and cut up a tennis ball in two, as it will be used to hide the cables inside the eye, while offering a place to hot glue the led strips.

Hot soldering action!

Hot soldering action!

Tennis anyone?

Tennis anyone?

Making good use of the butchered tennis ball

Making good use of the butchered tennis ball

I can see!!

I can see!!

But lighting wasn’t the only reason I ran cables inside my deadmau5 head. One issue which wasn’t addressed in any of the tutorials I saw was ventilation. You’re gonna spend several hours lugging a big plastic sphere on your head, breathing out a pantyhose. Condensation is gonna build up and you’ll start resenting your own creation. I needed to make sure fresh air was flowing into my mau5head – so I went and bought myself a computer fan. I actually got my hands on a unique model which used the same 9v voltage as the led strips (well 12v, but that just meant it would operate a little weaker), and also had a pretty mean blast of air compared to regular fans. I think it was this model (threw away the box so I’m not sure). In order to accommodate the fan I cut up a square hole in the back, into which I could slide in the fan, which was promptly secured into its place with some hot glue and zip-ties.

Yep, it's a fan.

Yep, it's a fan.

Fitted, hot glued and zip tied!

Fitted, hot glued and zip tied!

Rear view - after adding a mesh to prevent... "finger-related accidents"

Rear view - after adding a mesh to prevent... "finger-related accidents"

The led strips and the fan were connected using a parallel circuit, which got its “juice” from a small 9v battery at the end of approx. 1.5 meters length of wire, which was covered in duct tape to make it a bit more resilient.

Tethered power source

Tethered power source

The power source included the on/off switch. Very handy.

The power source included the on/off switch. Very handy.

Everything powered by this itty-bitty battery. Each one lasted for 2-3 hours.

Everything powered by this itty-bitty battery. Each one lasted for 2-3 hours.

In retrospect, I should have also made the cable easily detachable near the head, allowing me to more easily remove the mau5head when I wanted to give my neck some rest, or simply to return to my human form for a few minutes :-)

The final missing piece was the mouth. I bought one of those metal baskets which you hang in the shower to hold your shampoos and soaps and whatnot, and cut out the mouth from it:

Mouth grill - front

Mouth grill - front

Mouth grill - side

Mouth grill - side

I covered the mouth grill with a low density (20 denir) white pantyhose, stretching it until I was satisfied with the visibility. I then fastened it to the inside of the mouth opening using some foam tape and zip-ties. It was important I use strong material for the mouth (and not some flimsy mesh), since cutting out such a big piece of the bottom hemisphere made the head a bit… “wobbly”. The added mouth really boosted the head’s structural integrity.

Once everything was in place and working (the lighting and the fan), I hot glued the eye covers and tried it on!

See the chin?

See the chin?

This is where you can see how my chin protrudes from the bottom :-(

So I “hacked” the helmet (moving the harness which sits on my head deeper inside the helmet), smoothed out some places for added comfort and here is how it looked on Purim:

At the Tel-Aviv Purim street party

At the Tel-Aviv Purim street party

The bunny dude saw my fan and almost cried...

The bunny dude saw my fan and almost cried...

Nananananana... Batman!

Nananananana... Batman!

At the Mashina-Infected Mushroom concert!

At the Mashina-Infected Mushroom concert!

A severe case of pinkeye.

A severe case of pinkeye.

A severe case of pink eye

I really should have that looked at.

Walking with my deadmau5 custome was a weird/awesome experience. The reactions I got were crazy. Since you look so cartoonish, people’s reactions become… uninhibited. I was hugged, poked, lightly smacked and generally treated like an attraction. I was photographed with so many people, at some point I thought of all the money I could have made if I had gotten a sponsor :-)

On the other hand, since you are inside a mask, people can’t see your face, and therefore your reactions, which adds a whole different dimension to the experience.

Overall – it was a lot of fun (and the fan came through like a champ – the only issue with wearing the mau5head was the weight, no heat/condensation problems) , and I’m sure I’ll make use of my mau5head at least one more time sometime in the future.


My experience in the Google ̶̶S̶w̶e̶a̶t̶s̶h̶o̶p̶ Workshop

November 20, 2011

I recently attended GDD 2011 (Spoiler alert: the Android Ice Cream Sandwich OS has some nifty features. Beam for instance), which took me down memory lane and reminded me of the Google workshop I attended during my CS BA studies, back in 2010. I posted a link to our project in this blog.

not available for iPhone

The ‘workshop’ is a project every CS graduate from Tel-Aviv University is required to complete. You usually have a choice of around 10-20 workshops (there are more workshops during the 2nd semester), with workshops varying from creating a small robot which will be able to traverse an obstacle course (with a real robot), to more complicated optimal-path finding algorithms, computer vision related projects, machine learning, various mobile-based applications and much more. A relatively new workshop that was available was the Google workshop.

Obviously it was in great demand for having ‘Google’ in its name (the TAU method of getting the courses you want each semester is based on a bidding system. You receive points according to your XP, i.e. how many courses you already completed, and then use those points to bid on courses).

After talking with some of my classmates who completed other workshops, I realize that the Google workshop was one of the only workshops that placed emphasis on Milestones. Milestones were meetings we had about once a month, during which each team held a 15-20 minutes presentation, first discussing its project, and later on its progress on what it promised to complete by that milestone, as well as what we intend to complete next (our objectives). In most other workshops the groups met a couple of times when the semester began, and then the professor pretty much left you alone until you were required to hand in the project at the end of the semester, usually a couple of months after finals ended.

Looking back on it now, the Google workshop, in many ways, prepares its students much better for the scary ‘outside world’. As a programmer you need to be able to write elegant code, but also to give proper estimates as to how long it will take you to write that code. Give an ‘easy’ estimate (“Create a ‘contact us’ form? Oh, about a month’s worth of work”) and you’ll quickly be marked as an inefficient worker. Provide a ‘hard’ estimate (“Design the application’s database? I can whip that up in a day!”) – and it’ll quickly backfire on you. Just like goldilocks, you have to find that sweet spot in the middle. As someone with little or no experience that might prove difficult, but no one said it would be easy.

Another real-world aspect of the workshop was that we got very little ‘references’ from the team. That might seem unfair, unprofessional or perhaps plain old cruel, but in reality – it isn’t too far off from what you’ll face when you start working somewhere. Sure, there’ll probably be more experienced developers on your team who could offer you pointers, and if it’s a big company it might even have an organized system of training new recruits, but your autodidacticism skills will always be put to the test.

We also had to decide how to implement everything ourselves, even in terms of which platform to use. For instance, the workshop instructors introduced us to GWT (when I say introduced I mean that they let us know of its existence and where we can read about it), but didn’t require us to use it. If you haven’t heard of GWT, I recommend reading a little bit about it. It’s an interesting concept. I currently develop using the GWT platform, and I believe it is here to stay. I might even write a post about it soon (if I get around to it). We eventually opted against using it, and I’m pretty sure it was the right thing to do (it was probably “over-kill” for our purposes). But had we chosen to use it, and were to fall behind on our schedule as a result – we would have to face the consequences, or pull very long all-nighters. We couldn’t blame the instructors if it turned out that GWT was unsuitable for our purposes. It was our responsibility to properly research the technology we chose before using it.

Like I said, our workshop conditions were somewhat more difficult than that of the real world, but like we say in the IDF: “Kashe Ba’Imunim, Kal Ba’Krav”, which translates to “The harder the training, the easier the battle”, or to quote General George S. Patton – “Pressure makes diamonds”.


Clientside JavaScript goodness

July 29, 2011

As part of the hiring process to a certain company, I was asked to create a basic RIA (Rich Internet Application), with the primary focus on the client side (there doesn’t even have to be any actual communication with the server – all data can be created as mock data inside the js). Feeling a bit inspired, I decided to document how I went about it. First off, the assignment stated that if I use HTML5 for storage, I’ll get bonus points. I think I should lose points for using it, since it appears it’ll make my life so much easier. HTML5 allows you to save data on the client end, either for the current session (i.e the current window/tab) or for the entire time the user’s browser is open (i.e. across all pages in your domain). No need to send data back to the server or use other hacks. Yes, a cookie does the exact same thing, but a cookie’s “destiny” (and as a result – its size and robustness) is to save small stuff, like preferences or a user ID (which entails going back to the server for additional data. Every time, on every page). HTML5 lets you save almost any data structure inside a mapped data structure (a dictionary). Now obviously this raises quite a few security concerns. But you just have to think a bit about what you decide to save on the client side. Since this is a “mock” project, that will not be an issue. So first things first, let’s set up a quick web site. I’ll use Google WebAppEngine – it’s fast and easy. So you can see what I did here. We also need somewhere to host the code. Google to the rescue once more. Since my server side is going to be meaningless (I only load static HTML pages, with no content provided from the server), I better see how to configure app.yaml so it’ll route my urls properly:

application: apple-of-israel version: 1 runtime: python api_version: 1 handlers: – url: /stylesheets static_dir: stylesheets – url: /static static_dir: static – url: /js static_dir: js – url: /index static_files: static/index.html upload: static/(.*) – url: /employees static_files: static/employees.html upload: static/(.*) – url: /.* script: helloworld.py

this configuration means that when I navigate to localhost:8080/index – I get referred to my index.html file. The same for employees. For now I left the helloworld routing – which means that localhost:8080/ routs to a phython script, which prints an html of hello world. I could have used that routing to create my html in python, but that just seems silly, and also defeats the purpose of taking the load off the server and having the client do all the work. The static redirection is needed for hrefs inside the html pages that link to other static html pages in the site. The stylesheets redirection is needed for when my html pages request the css file inside the stylesheets folder. “Which css?” you ask? The one I got for free here. The js folder routing is for javascript files. obviously. OK, let’s attempt and store some data between pages using our newfangled HTML5. We’ll add this code to index.html:

<script type=”text/javascript”>

sessionStorage.setItem(‘userName’, ‘tom’);              // defining the session variable

alert(“Your user is: ” + sessionStorage.getItem(‘userName’));   // accessing it

alert(“Hello ” + sessionStorage.userName);                   // another way of accessing the variable

</script>

and the following code to districtNorth.html:

<script type=”text/javascript”>

sessionStorage.setItem(‘userName’, ‘tom’);              // defining the session variable

alert(“Your user is: ” + sessionStorage.getItem(‘userName’));   // accessing it

alert(“Hello ” + sessionStorage.userName);                   // another way of accessing the variable

</script>

Well, that was pretty easy. So I am now able to move around different static HTML pages, and I also have a local datastore. Awesome. Time to create my mock data, find some cool javascript libraries and start using and manipulating that data. Well, the mission mostly required me to display a list of people who pick apples in different sectors of Israel. The actions which a user could perform were listed. So naturally, I started with creating mock data of bunch of apple pickers.

Late edit – due to having to finish the task on time, I kinda stopped writing about what I’m doing at this point. For some reason I haven’t published this post right away (probably felt ashamed at not documenting the entire process).

also , if anyone is interested in knowing – I got the job :-)


Research Assistant – organize your papers

August 29, 2010

As part of a Computer Science project, some friends and I built a site which helps you (the Google Scholar user), manage your research, stay updated and collaborate with colleagues.

http://research-assistant.appspot.com/

You log in using your Gmail account (the site is hosted on Google’s servers), so no need to register and fill out any details.

I hope you find it useful!


Exam period

July 20, 2010

One of the subjects on which I’ll be tested soon is computational complexity . This great short story by Isaac Asimov turns out to be linked to this subject. A very interesting read:
http://www.multivax.com////last_question.html


Getting in touch with your inner log()

February 18, 2010

Neuroscience is on the rise. Every other week you hear about a new discovery, or simply the next step in computing, gaming and… board-games (???).

I have always been fascinated by the human brain (well, consider the source being fascinated :-P), so when I saw a class opening up on the subject in my university, I immediately signed up for it.
The basic goal of neuroscience is to reverse-engineer a complete blueprint of the brain. I am not simply referring to its actual physical makeup:

The interesting part is how it actually works. Its API if you will, or “instructions”. One of the main topics covered in this class was sight. Most of us are familiar with the “lies-to-children” version of how vision works:

(click to enlarge)

Well, the human brain does perform some sort of transformation, but it is a much more useful one.
To simplify matters, let’s consider the surface of the human eye (more specifically, the cornea) to be a round disc (like a vinyl music record). I assume all of you are familiar with Cartesian coordinates, or more commonly known as X-Y coordinates. Well, Cartesian coordinates are very convenient when working with square surfaces (like a map or graph), but not so well when the surface is circular. A more appropriate approach would be to use a Polar coordinate system. Instead of the two values X and Y, we have R and θ (Theta); R being the length of the straight line between the center of the circle and the point, and Theta indicating the angle between that straight line and the horizon. For example:

Everybody knows that the right part of the brain controls most of the left side of the body and vice versa. Well, in the field of vision it’s a bit more complicated. The left side of the brain does not handle visual information from the right eye, but from the right field of vision. So it will handle data from the right side of the right eye, and from the right side of the left eye. But that is less relevant for what I want to talk about, and we could just as well assume we are all Cyclops, i.e. we only have one eye (the second eye is important for detecting depth, but that’s a whole other subject by itself). That means the left side of the brain handles information from the right side of that eye and vice versa.

The part which is first in line to handle information from the eyes and is in charge of sending the most “raw” data about what we see to the rest of the brain is called the visual cortex. Again, we simplify its surface area to make things clearer. With that in mind, one could consider the visual cortex to be rectangular.

So suppose a beam of light hit our eyes. What happens now? The same image will be replicated on the visual cortex, but it will do so after undergoing a transformation along the way. That transformation will take the parameters R and Theta, and will display them on the visual cortex, in Cartesian coordinates – the Y value will be equal to Theta (in radians), and the X value will be equal to log(R). That’s right. The function log(). The one in your calculator.

After you get over the initial shock of realizing that your brain is carrying out log calculations as you are reading these words (Yes, even now. And now. :-P), you start thinking – “why log?”; “what makes it so special?”; The only possible answer comes to mind – evolution.

First you must realize that we do not see 3 dimensions. Sure, we’re all experts at not bumping into things, but we have no receptors for depth. Our eye is flat, and everything we see can be considered to be a 2D image, just like the ones on television. So how come we still have fighter pilots? Our brain uses very elegant algorithms to determine parameters such as depth from the image it receives. One of the algorithms relies on this log transformation – it helps us detect movement. Consider a 2D surface (we’ll consider a circular 2D area – the surface of our eye). A 2D object on that flat surface can transform in three ways:

(if you don’t see any animation, click on the images)

Scaling:

Rotating:

and Transitioning:

Think about what each of these transformations mean in the real world. Suppose something is becoming bigger and bigger in your field of vision… you should probably duck for cover. Rotation is another good indicator that something is being hurled at you, or simply moving in a manner which you should pay attention to, unless you want to finish your day as fast food. Meaning you would probably want to decide to duck/run/attack as fast as you can. That’s where log comes in. Suppose you were the programmer of the human brain. And you need to build an algorithm which detects objects growing in size. Remember – we don’t see things getting closer. We just see them getting bigger. Look at the animated scale gif. Your algorithm needs to detect that the same object is growing in all directions. That will probably not be such a time efficient algorithm. The same goes for detecting rotation (we will get to transition later). This is where the beauty of log comes in. The mathematical qualities of this function dictate that if someone throws a wrench in your direction, the image shown on your visual cortex will resemble this:

(left side – what your eye “sees”. right side – what your visual cortex “sees”.)

In general, scaling will be transformed into movement of the same sized object along the X axis, while rotation will be transformed into movement of the same sized object along the Y axis. The algorithm for detecting such change is much more time efficient. The reason our brain uses the log function stems simply from evolution – it’s a good way to detect danger, so we use it (when I say “we”, I obviously don’t mean just human beings. This didn’t happen overnight :-)).

I haven’t discussed the last possible movement – transition. But we get over that obstacle using our eyes themselves. Place your finger between you and your monitor. Focus on your finger. Now start moving it in front of you. Almost instinctively, your eyes will follow your finger, leaving it in the middle of your field of vision, effectively nullifying its transition. So that’s how we deal with transition.

Bear in mind: “If the brain were so simple we could understand it, we would be so simple we couldn’t.” – Lyall Watson


Follow

Get every new post delivered to your Inbox.