Skip to content

Instantly share code, notes, and snippets.

@dawnerd
dawnerd / mkv2mp4.sh
Created May 17, 2012 20:53
Converts an mkv to mp4
#!/bin/bash
# Converts a file from mkv to mp4.
# Shortcut for the following
# HandBrakeCLI --preset="Normal" -i Zombieland-720P.mkv -o Zombieland-720P.mp4 -O
#
# Usage: mkv2mp4 sourcefile.mkv
output=`echo $1|sed -e "s/.mkv/.mp4/gi"`
echo "Encoding $output"
@dawnerd
dawnerd / simpleif.js
Created April 20, 2012 21:43
Simple If
function simpleIf(fun_if, fun_else) {
if(!fun_if()) fun_else();
}
//usage
simpleIf(function(){
console.log('doing stuff because Im true!');
return true;
}, function(){
console.log('some more stuff :(');
@dawnerd
dawnerd / debounce.html
Created April 10, 2012 00:07
debounce solution
<html>
<body onload="onLoad()">
<script>
function onLoad(){
var UserInput = document.getElementById('UserInput');
var UserOutput = document.getElementById('UserOutput');
//YOUR CODE HERE
Function.prototype.debounce = function(delay_period) {
@dawnerd
dawnerd / debounce.txt
Created April 9, 2012 21:13
Debounce JS programming challenge
Debounce
Debouncing is a way of ensuring that a function is only called once when fired multiple times in a short period. Almost all keyboards have some form of built in debouncing since the keys will hit the sensor quite a few times per keystroke. For keyboards, the delay is somewhere around 50ms.
In Javascript, debouncing is important for rapidly firing events, such as text input. Instead of firing a keydown event and processing input data on every keypress, you fire the event once after no more keypresses are detected in a certain amount of time.
--
Scoring:
1 point for correctly working solution
function reverse(input){
return '&#8238;'+input;
}
document.body.innerHTML = reverse('this is a test')
var foo = Math.PI;
//Most common
Math.floor(foo);
//Double bitwise NOT
~~foo;
//Bitwise OR
foo | foo;
var foo = Math.PI;
Number(foo);
parseInt(foo, 10);
var easings = {
bacon: function(pos) {
return 1 - (Math.cos(pos * 2 * Math.PI) * Math.exp(-pos * 5));
}
};
@dawnerd
dawnerd / parseTweet.js
Created December 16, 2011 02:38
Parse Tweet text
function parseTweet(text) {
return text.replace(/[\w]+:\/\/[\w\d-]+\.[\w\d-:%&~\?\/.=]+/gi, function(url) {
return url.link(url);
}).replace(/[@]+[\w\d-]+/gi, function(u) {
return u.link("http://twitter.com/"+u.replace("@",""));
}).replace(/[#]+[\w\d-]+/gi, function(t) {
return t.link("http://search.twitter.com/search?q="+t.replace("#","%23"));
});
}
@dawnerd
dawnerd / gitprompt.sh
Created December 14, 2011 18:36
gitprompt
c_cyan=`tput setaf 6`
c_red=`tput setaf 1`
c_green=`tput setaf 2`
c_sgr0=`tput sgr0`
parse_git_branch ()
{
if git rev-parse --git-dir >/dev/null 2>&1
then
gitver=$(git branch 2>/dev/null| sed -n '/^\*/s/^\* //p')