It rained, it snowed, but hey it’s Friday! Grab some beers and snack on some links.
Now you can exchange bitcoins to buy apps, games, and more at Microsoft
It’s a post Ballmer world and Microsoft is making big moves. Starting immediately, you can use Bitcoin to fund your Microsoft account to buy apps and Xbox content. Get the details >
Async – Cooperative Multitasking for Hack
Evaluating Facebook’s new Hack programming language? Well check out how it supports cooperative multitasking. Hint: It’s pretty sweet. Read more >
Keurig 2.0 DRM Bypass
Have a shiny new Keurig 2.0 but don’t want to pay for the premium K-cups? Well KeurigHack has you covered. Get some scotch tape and drink those cups. Details here
Obama Becomes First President to Write a Computer Program
In support of CS education and the “Hour of code” project, President Obama wrote some Javascript. Rumor has it a fist bump was also involved. Read the story >
A couple of months ago I was at Firebrand Saints and started wondering how the effects that they run on their videos work. At Firebrand, their main bar has a few flat screen TVs showing cable channels you’d expect but every now and then one of the TVs will start displaying the video through a filter. So as you’re sitting at the bar you’ll notice Sportcenter go from regular video to what looks like Sportcenter put through a pixelated filter. Unfortunately, the fall got a bit busy and I forgot to jot this down but it recently came back to me while watching the Family Guy – Take On Me skit.
So how do you programmatically apply effects to video? After some searching around, it seems like the preferred way to do this is to convert the video to a series of images, apply the effects, and then encode the images back to a video. Since we’re on Linux the weapons of choice for this are libav (ffmpeg fork) and ImageMagick. Additionally, I used youtube-dl to grab some source video from YouTube.
Playing around with manipulating videos and images is pretty CPU intensive so I decided to do this on a c3.xlarge. Once you have a machine up, just run the following to get everything setup:
Now, snag yourself a video from YouTube:
Next, you’ll want to extract the audio and then the individual frames from the video:
And now for the fun part – time to apply some effects to the image! As an fun first pass I ran the “paint” transform across the images. PS. Remember how we launched on that c3.xlarge? Well now we can run the transforms in parallel with xargs:
Finally, you’ll need to encode the images back together into a video format of your choice:
Here’s a clip of the video I ended up with:
So what else can you do with this? Well that’s the awesome part! An image manipulations you can do programmatically (ImageMagick, NodeJS, etc.) you can apply to your video.
Perhaps some Mystery Science Taylor Swift?
Unfortunately this adventure has left me with more questions than answers:
How do you apply filters to a video in real time?
Would it be possible to integrate this into a rooted (or stock) Chromecast?
Could you build something to support user interactivity? Maybe with Canvas/nodeJS?
It’s Friday, you did it! To bootstrap your weekend we’ve got some kickass links from the last week.
Mean People Fail
Did you know that mean people are unsuccessful startup founders because being mean makes them stupid. We certainly didn’t. Check out why and other reasons being mean will lead to failure. Read the essay >
You sure you’re not a robot?
Google is making life easier by revising reCAPTCHA. Instead of those pesky distorted texts that you had to type to enter a website, there’s now a “i’m not a robot” box option for you to click. Sadly, you might still need to read and type distorted texts after clicking the box, but you could also come across a new feature where you match pictures of animals. Check it out >
Here’s Crayon for your Web Page
All the web pages in the world, and we mean all, can be found at Crayon. Housing a massive collection of web pages (hence crayon), inspiration and ideas are bound to happen, culminating to an impressive web page for you. Check it out >
quaggaJS: Barcode Scanner
Written entirely in Javascript, QuaggaJS is a barcode scanner that supports real time localization and decoding of various barcodes. All you need to fire it up is a browser that supports the getUserMedia API. Check it out >
With Symfony2 the firewall comes with a built in feature: impersonate a user. We’ve been using impersonation as an admin tool for about 5 years as it is very effective for troubleshooting. When a user files a support ticket saying something isn’t showing properly to them or they are getting random errors it is very easy to just quickly switch to that user and see what they are seeing. As with all features, this one may not be appropriate for your application if your user expects no administrative staff to have access to his or her account.
While Symfony’s built in impersonation feature is a great step up from having to build it by hand, it still can be a bit more friendly. We’ve seen two additional functions we wanted the impersonation to handle. First, we wanted it to on exit from impersonating the user returns the user to where the user first started to impersonating. Currently it just brings you back to wherever you link the user. Second, if already impersonating a user and trying to start to impersonate another, we didn’t want it to throw an error but to quietly switch you. This functionality could lead to unwanted circumstances if an impersonating user believes they can impersonate another user, and then slowly just keep exiting impersonation of each user and go back up the chain they went down. However, in our situation the time admins hit this was when they’d impersonate one user, realize they clicked the wrong one, click back and try to impersonate a different user. As the browser uses it’s cached page when the user hits back they see the list of users as if they were an admin and can click on the correct user. If they do this they are hit with a 500 error, “You are already switched to X user”.
For both of our goals we overrode the built in switch user class. It is really easy to override, as all you need to do is specify in your parameters.yml “security.authentication.switchuser_listener.class: My\AppBundle\Listener\SwitchUser”. We used the built in class as our starting template: https://github.com/symfony/symfony/blob/2.5/src/Symfony/Component/Security/Http/Firewall/SwitchUserListener.php Our final class ended looking like:
Here are the specifics on what everything we did and why.
First feature: Redirecting the user on exiting impersonating a user to where they originally started impersonating them. As we didn’t want to go around our entire application updating logic for the exit impersonation links if we decided to later change the behavior, we decided to build the redirect into the class itself. We didn’t want to rely on the user’s browser referrer header, so instead we decided to on the links to impersonate a user to include a “returnTo” parameter. This parameter is set to the current URI (app.request.uri). At line 97 we save the returnTo parameter to the session, for later use. On line 93, as a user is switching (in this case exiting) a user, if the session has a stored “returnTo” URL, we assign it to the “$overrideURI” variable. On line 107 we have a bit of logic on if we redirect them to the default route or the “returnTo” URL. The reason for the additional “$this->useOverrideURI” variable on this line is for our second feature of switching between users when you are already impersonating one. As the logic all runs through the same routine, if you are simply switching to a new user from an already impersonated one, we don’t want to redirect you back to your original URL when you started all the impersonating, so we disregard the redirect in this case and redirect to the default route. An example of this is admin impersonates user A, then wants to impersonate user B. Upon impersonating user B, the admin does not want to be redirected back to the admin dashboard (the sessions returnTo URL), but to where the impersonate user link is pointing to (User B homepage).
Second feature: Allow users to impersonate a different user while already impersonating another. One Line 134 is where the original SwitchUserListener would usually throw a 500 error as you are already impersonating a user. Instead, we make sure that the original token has the appropriate permissions, if so it will not throw an exception. Line 159 is the other main update for this feature. If you are already impersonating a user and try to impersonate another user, upon exiting you want to go back to your original user. Now if a original impersonation token (user) exists, we keep that as the user you’ll be switched to when you exit the impersonation.