This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Accelerometer Javascript example by @karlwestin, Nerd Communications, Berlin | |
// Firefox, works on desktop too | |
window.addEventListener("MozOrientation", updateText, true); | |
// Mobile Safari | |
window.addEventListener("devicemotion", updateText, true); | |
function updateText(e) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# this can be put in [repo]/.git/config for local settings | |
# or ~/.gitconfig for global settings | |
# create a difftool "nodiff" that just returns true | |
# this path is for Mac. On linux it's /bin/true i guess | |
[diff "nodiff"] | |
command = /usr/bin/true | |
# make git ignore white space differences, many different possibilites here |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// On Arduino Uno 2.2 | |
// Using Examples > Firmata > StandardFirmata_2_2_forUNO_0_3 | |
var firmata = require("./firmata/lib/firmata"); | |
var board = new firmata.Board("/dev/tty.usbmodem621"); | |
board; // logs board object, board.pins is empty | |
board.digitalWrite(2, 1); // generates error can't write value to undefined |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$(document).ready(changer); | |
function changer() { | |
var imgnum = Math.floor(15 * Math.random()); | |
var time = Math.floor(5000 * Math.random()); | |
var $img = $('.project_thumb .cardimgcrop img').eq(imgnum); | |
var newsrc = "http://yaplog.jp/cv/omb-master/img/449/noise_p.gif"; | |
$img.css({ | |
'width': $img.css('width'), |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'digest/sha1' | |
(1..10000).map {|n| (Digest::SHA1.hexdigest (n*rand).to_s)[1..8]} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// while reading: http://compositecode.com/2011/09/27/code-katas-kicking-off-with-a-little-javascript/ | |
function romanToArabic(roman) { | |
var letters = ["M", "D", "C", "L", "X", "V", "I"], | |
values = { M: 1000, D: 500, C: 100, L: 50, X: 10, V: 5, I: 1 }, | |
sum = 0; | |
for(var i=0; i<roman.length; i++) { | |
if (typeof roman[i+1]!= "undefined" && letters.indexOf(roman[i]) > letters.indexOf(roman[i+1]) ) { | |
sum += values[roman[i+1]] - values[roman[i]]; | |
i++; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function romanToArabic(roman) { | |
var ones = 0, | |
fives = 0, | |
tens = 0, | |
fifties = 0, | |
result = 0, | |
lCount = roman.split(/L/g).length -1, | |
xCount = roman.split(/X/g).length -1, | |
vCount = roman.split(/V/g).length -1, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// This is the implementation from https://github.com/zachleat/JavaScript-Code-Katas | |
Game.prototype.score = function() | |
{ | |
var points = 0, | |
frameIndex = 0; | |
for(var frame = 0; frame<10; frame++) { | |
if(this.isStrike(frameIndex)) { | |
points += this.strikeBonus(frameIndex); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var score = function() { | |
var score = 0; | |
for(var i = 0; i < 10; i++) { | |
if(rolls[0] === 10) | |
score += rolls.shift() + rolls[0] + rolls[1]; | |
else if(rolls[0] + rolls[1] === 10) | |
score += rolls.shift() + rolls.shift() + rolls[0]; | |
else | |
score += rolls.shift() + rolls.shift(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var arr = [1,2,3,4,5,6,7]; | |
var first = arr.shift(); // first = 1, arr = [2,3,4,5,6,7] | |
arr.unshift(0); // arr = [0,2,3,4,5,6,7] | |
arr.push(8); // arr = [0,2,3,4,5,6,7,8] | |
var last = arr.pop() // last = 8, arr = [0,2,3,4,5,6,7] |
OlderNewer