Coconut Monarchy

Creative problems.

Arduino + Serato DJ = Seratuino

I had the chance to play with Mixxx lately, and I was intrigued particularly by the vinyl control which lets you manipulate the playback of a song using a turntable as an interface. Vinyl control uses special timecoded records which are placed on real turntables. The audio reproduced is then processed by the software, which uses those information to manipulate whatever song is loaded.

Turns out that the timecode is basically two sinewaves that are (almost) 90 degrees phase shifted, so I wondered if I was able to generate the same waves pragmatically.

Fortunately, the answer came the guys from lab3 who published an article about an Arduino Sine wave Generator using the direct digital synthesis Method. Despite I completed ignored the low pass filter section, I was able to successfully generate one sine wave.

At that point all I had to do was adding a potentiometer to control the frequency of the wave and calling the dds function with arguments “shifted” so I could get the phase shifted by 90 degrees.

This is the schematic:

And here you can find the arduino sketch.

Don’t forget me know what you think! Follow me on Twitter!

UPDATED workaround for disabled download button on SlideShare

It’s been almost one year since I built the first script to download protected presentation on Slideshare. Many people complained that the script was to techie and wasn’t working all the time. They were right.

I decided to revisit the script and make it simpler. This is what I’ve got: a nice mac app that given the url, downloads the presentation.

You can download the app here

Let me if it works for you in the comments! You can also follow me on twitter!

Dribbble Invite Competition

Hello everybody!

Recently, I received one dribble invite to give away! So here is your oppurtunity to be part of this amazingly creative community!

This invitation is going to go down to quality work. I don’t want to invite users who I don’t think meet the standards. To be in for a chance, you just need to complete the three steps below:

  1. Make a comment on this post and link to one 400 x 300 px shot. The subject of the shot is “trip roulette”. What’s your first thought about that name? Let me know in your shot!
  2. Send a tweet that says (copy exactly):
    Dribbble Invite Competition: @danielepolencic offers 1 Dribbble Invite. Tweet this message to enter the contest. Details: bit.ly/HgzF4E
  3. There is no step 3 ;)

Remember to follow my twitter account or double check this page the 9th of April because that’s where and when I will announce the winner!

Good Luck!

Faster sprite generation with Spritemapper

Optimizing images to reduce HTTP requests is a very time-consuming task. Recently, I was required to make a sprite from a bunch of sponsor images. Each of them has two states: it’s grayscale when is inactive, but becomes colored on mouse over. Thus in total, I had twice as much images. Also, all the images had different sizes.

Building the sprite manually would be terribly time consuming, therefore I came up with a simple python script which:

  • reads the image width and height
  • checks if the grayscale version exists
  • creates a new grayscale version of the image if necessary
  • writes the css for that image

The code for this simple script is (requires the PIL library):

import subprocess
import os
import re

from PIL import Image

images_path = "./logos/"
css_file = open( "sprite.css", "w" )

for subdir, dirs, files in os.walk( images_path ):
   for file in files:
      file_name, file_extension = os.path.splitext( file )
      if re.search( r'\.png', file_extension ) and not re.search( r'_bn$', file_name ):
         image = Image.open( images_path + file )
         width, height = image.size
         print "w: %d h: %d name: %s ext: %s" % ( width, height, file_name, file_extension )
         image_bn = file_name + '_bn' + file_extension
         if not os.path.isfile( images_path + image_bn ):
            image = image.convert( "L" )
            image = image.convert( "RGB" )
            image.save( images_path + image_bn )
         else:
            print "file found"
         css = """#%s { background: url(%s%s); width: %dpx; height: %dpx; }\n#%s:hover { background: url(%s%s); }\n""" % ( file_name, images_path, image_bn, width, height, file_name, images_path, file )
         css_file.write( css )

css_file.close()

The next step is optimizing the images using css sprites. After saving all the sponsors in the designed folder, I used Spritemapper to automatically parse and generate the files:

~$ python script.py
~$ spritemapper sprite.css

None are willing to share their own bonus

A group of seven bankers are gathered for an evening meal to celebrate bonus day. They have all received bonuses, but for different amounts, and each is unaware of what the others received. They are all eager to know whether their bonus is higher or lower than the average, but none are willing to share details of their own bonus.

How could they work out the mean average of their bonuses, with no help from anyone else, and without any of the seven participants becoming aware of the value of any individual bonus other than their own?

The Cube Calendar

The cube calendar consists of a plurality of cubes supported by a holder having month and day printed on the sides of the cubes. Assuming that you would like to build just the two cubes for the days, how do you print the numbers such as with just two cubes you are able to display all the days for the entire month (from the 1st to the 31st)?

Workaround for disabled download button on SlideShare

UPDATE #2: new workaround here!
UPDATE #1: Wordpress breaks the code everytime I update the article. I decided to mirror the code here https://gist.github.com/2471903

Disclaimer: This is a proof of concept. I’m not responsible if you are going to against the terms and conditions of slideshare.
I found really annoying when I cannot download a presentation from SlideShare because the download button is disabled. I don’t want to steal someone else work, but I’d like to just make a note of the presentation in Evernote, so that it can be indexed for later consumption. After googling just a little bit, I realized that there is no easy way to do that and I wrote my own script.

#!/bin/bash

# http://cdn.slidesharecdn.com/2011-awstour-australiasimone-brunozzi-110714123227-phpapp01-slide-24.swf?ver=1311305480

if [[ $# != 3 || $(echo $2 | egrep ^[[:digit:]]+$) = "" ]]
then
   echo "Usage: $0 url pages version"
   echo "Example: $0 http://cdn.slidesharecdn.com/2011-awstour-australiasimone-brunozzi-110714123227-phpapp01-slide 85 1311305480"
   exit 1
fi

# check if swfrender (swftools) exists.
hash swfrender 2>&- || { echo >&2 "I require swfrender (package swftools) but it's not installed.  Aborting."; exit 1; }
# check if convert (imagick) exists.
hash convert 2>&- || { echo >&2 "I require convert (package imagick) but it's not installed.  Aborting."; exit 1; }

rm slide.pdf >/dev/null 2>&1
rm -r tmp >/dev/null 2>&1
mkdir tmp

for ((i = 1; i <= $2; i++));
do
   link="$1-$i.swf?ver=$3"
   slide=`printf "tmp/slide-%03d.swf" $i`
   # echo "$link"
   # echo $slide
   curl $link --O $slide
   swfrender $slide -o "$slide.png"
done

echo "Combining the slides together..."
convert tmp/*.png slide.pdf
rm -r tmp >/dev/null 2>&1
./download.sh url n_of_pages version_number

The version number may be optional, but you are encouraged forced to write it down. You can find it in the net tab of firebug.

 

The Gravity Language

I have been tested my skills with a pretty neat exercise. The test requires to write a small program that sums two random numbers with an unknown programming language called Gravity.
The language itself is very simple: it is possible to manipulate variables with three basic operations but only inside the stack.
The language has three basic operations:

  • Z_i

    Set the ith element of the stack to zero

  • I_i

    Increment the ith element by one

  • J_i_j

    Compare the ith and jth elements and jump if they are different

The stack looks like an array:

+---+---+---+---+---+---+---+---+
|   |   |   |   |   |   |   |   |
+---+---+---+---+---+---+---+---+
  0   1   2   3   4   5   6   7

Let’s assume we want to compare two numbers stored in the first two position of the stack and set the fourth element to one if the numbers are different:

 Z_0
 Z_1
 I_1
 J_0_1 +--+
 END      |
 I_4   <--+
 END

If we take 2 and 3 and we compare them, the stack will look like:

+---+---+---+---+---+---+---+---+
| 2 | 3 |   |   | 1 |   |   |   |
+---+---+---+---+---+---+---+---+
  0   1   2   3   4   5   6   7

Cool! Now that you are fimiliar with the language the not-so-trivial question: can you write an algorithm that sums two numbers?

Hello Coconuts!

Hello! Coconut Monarchy is a place where we can show bits of what we’re working on, talk about coding, and share our excitement over the tools that help us create.