Skip to content

Instantly share code, notes, and snippets.

View olistik's full-sized avatar

Maurizio De Magnis olistik

View GitHub Profile
/* workaround for 2 bugs related to jQuery Tools Dateinput:
* 1) the initial value is wrongly set
* 2) "data-" attributes presents on the target input get wiped out
*/
$(":date[data-backend]").each(function() {
var backend_attr = $(this).attr("data-backend");
var value = $(backend_attr).val();
var year = parseInt(value.substring(0, 4), 10);
var month = parseInt(value.substring(4, 6), 10) - 1;
@olistik
olistik / openhash_in_rails3
Created December 12, 2010 21:58
How to use OpenHash in Rails 3
## UPDATE 2010-12-14: facets-2.9.0 and hashery-1.3.0 doesn't work with rails 3.0.3 (due to a bug of facets):
## https://github.com/rubyworks/hashery/issues#issue/6
## https://github.com/rubyworks/facets/issues/issue/31
## in your Gemfile
gem "facets"
gem "hashery"
## then execute in the shell
#!/usr/bin/env ruby
dictionary = ('a'..'z').to_a + ('A'..'Z').to_a + ('0'..'9').to_a
password = 1.upto(10).map {|i|
index = (rand * dictionary.size).to_i
dictionary[index]
}.join
puts "random password: #{password}"
@olistik
olistik / job_post_puzzle.rb
Created January 4, 2011 22:22
the sum of all multiples of 3 and 5 less than 1000
>> (1..1000).select {|x| (x % 3) == 0 && (x % 5) == 0}.inject(:+)
=> 33165
@olistik
olistik / hide_dot_files.sh
Created February 27, 2011 10:27
hide dot files from macosx (run from terminal)
defaults write com.apple.finder AppleShowAllFiles FALSE && killall Finder
@olistik
olistik / truste_endorsement_counter.sh
Created April 29, 2011 13:03
anonymously increment the endorsement counter of any given url at (notso)TRUSTe
#!/bin/bash
curl -d "url=www.myhomepage.com&page=validate&sealid=101&req_button=Positive&pageVersion=validationNewPage&test=1&urlBaseOn=%24urlBaseOn" "http://clicktoverify.truste.com/pvr.php?page=validate&url=www.myhomepage.com&sealid=101" >& /dev/null
@olistik
olistik / flv2web.sh
Created May 12, 2011 08:15
convert all the .flv contained in the current directory to .mp4 and to .webm
#!/bin/bash
ipad_preset_path="/Applications/Miro Video Converter.app/Contents/Resources/ffmpeg_presets/libx264-ipod640.ffpreset"
for filename in *.flv
do
echo "Converting video: $filename ... "
echo "Converting to mp4 ..."
ffmpeg -i "$filename" -threads 0 -strict experimental -f mp4 -vcodec libx264 -vpre slow -fpre "$ipad_preset_path" -b 1200k -acodec aac -ab 160000 -ac 2 "${filename%.*}.mp4"
echo "Done."
@olistik
olistik / gist:968153
Created May 12, 2011 08:16
miro preset for ipad's mp4 (/Applications/Miro Video Converter.app/Contents/Resources/ffmpeg_presets/)
We couldn’t find that file to show.
@olistik
olistik / poll_repository.sh
Created May 18, 2011 14:02
poll git repository
#!/bin/bash
while true; do
echo "Checking git repository.."
date -u
git_status=`git pull`
if [[ $git_status != *up-to-date* ]]; then
growlnotify -m "Repository updated" -s
else
echo "no updates"
if (Modernizr.video.h264) {
videoId = "#asd";
video = VideoJS.setup(videoId);
video.play();
} else {
videoUrl = 'KimAronson-TwentySeconds59483.flv';
$f("player1", "flowplayer.swf", {
clip: {
url: videoUrl,
autoPlay: true,