Skip to content

Instantly share code, notes, and snippets.

View lafeber's full-sized avatar

Martijn Lafeber lafeber

View GitHub Profile
@lafeber
lafeber / collatz.rb
Created October 29, 2021 09:45
Collatz conjecture
def collatz(i)
puts i
return if i==1
i.odd? ? collatz(3*i+1) : collatz(i/2)
end
@lafeber
lafeber / recursively_empty_logs.sh
Created November 22, 2018 09:47
Recursively empty log files.
find . -type f -name "*.log" -exec dd if=/dev/null of={} \;
@lafeber
lafeber / image-preview.css
Created August 31, 2016 10:40
basic simple_form input preview
.container{
margin-top:20px;
}
.image-preview-input {
position: relative;
overflow: hidden;
margin: 0px;
color: #333;
background-color: #fff;
border-color: #ccc;
# attributes.yml:
nl: &attributes
article:
title: Titel
short_title: Meta titel
# active_record.yml:
nl:
@lafeber
lafeber / gist:3755590
Created September 20, 2012 12:23
kanso server start failure
kanso push http://localhost:5984/example
Reading dependency tree...
loading .
preprocessor attachments/add
loading packages/attachments
postprocessor attachments/cleanup
Build complete: 21ms
Error: Error: connect ECONNREFUSED
at errnoException (net.js:769:11)
at Object.afterConnect [as oncomplete] (net.js:760:19)
@lafeber
lafeber / pushandpullfromcurrent
Created April 19, 2012 07:30
Always push and pull from current branch
git config --global push.default current
git config --global pull.default current
@lafeber
lafeber / locales.rake
Created August 16, 2011 08:44
A rake file for managing multiple large translation files
begin
require 'ya2yaml'
rescue LoadError
print "The locales tasks were not loaded, since ya2yaml gem is not present. Don't worry if this is a production machine, it is required for development only.\n"
else
LOCALES_PATHS = ["#{Rails.root}/config/locales/", "#{Rails.root}/config/locales/activerecord/", "#{Rails.root}/config/locales/authlogic/", "#{Rails.root}/config/locales/notification_templates/"]
MASTER_LOCALE = "en"
IGNORE_FILES = %w(en.yml en-UK.yml)
@lafeber
lafeber / replaceVideoWithFlash.js
Created June 6, 2011 13:58
Replace html5 video tag with flash
/** Replaces video tag (src=[file].mp4) with flash for Firefox, Opera and IE <9
Make sure you have flowplayer! (www.flowplayer.org)
width, height and src of the video should be set
*/
function replaceVideoWithFlash() {
if(navigator.userAgent.indexOf('Firefox') != -1 || navigator.userAgent.indexOf('Opera') != -1 || ( navigator.userAgent.indexOf('MSIE') != -1 && parseFloat(navigator.appVersion.split("MSIE")[1]) < 9 )) {
var videos = document.getElementsByTagName('video');
for(var i=0; i < videos.length ; i++) {
var video = videos[i];
var src = video['src'];
class Integer
def to_leading_zero_string
(self < 10) ? "0#{self}" : self
end
end
#To get all episodes of kabouter Wesley, where 21 is the amount of episodes
21.times do |i|
system "wget http://kabouterwesley.pro-networks.nl/afleveringen/aflevering_#{(i+1).to_leading_zero_string}.mp4"
end