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
YUI().use('node', 'gallery-yql', function (Y) { | |
new Y.yql('select * from github.user.repos where id = "emkay"', function (r) { | |
// do something with r | |
}); | |
}); |
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
<script src="http://yui.yahooapis.com/3.2.0/build/yui/yui-min.js"></script> |
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
<div id="twitter-feed-title" style="display:none;"> | |
<div id="twitter-feed"> | |
</div> | |
</div> |
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
YUI().use('node', 'gallery-yql', function (Y) { | |
new Y.yql('select * from twitter.user.timeline where id="someuser"', function (r) { | |
var len = r.query.results.statuses.status.length; | |
if (!r.error && len > 0) { | |
Y.one('#twitter-feed-title').setStyle('display', 'block'); | |
var t = Y.one('#twitter-feed'); | |
var status = r.query.results.statuses.status; | |
for (var i = 0; i < len; i++) { | |
t.append('<div class="status">'+status[i].user.name+'<p class="status">'+status[i].text+'</p></div>'); | |
} |
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 Card = function (rank, suit) { | |
this.rank = rank; | |
this.suit = suit; | |
this.getRank = function () { return this.rank; }; | |
this.softValue = function () { | |
var result = ''; | |
switch (this.rank) { | |
case 1: // Ace | |
result = 11; |
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.build = function () { | |
for (i = 1; i <= 4; i++) { | |
for (j = 1; j <= 13; j++) { | |
this.cards.push(new Card(j, this.suits[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
/* | |
* Fisher-Yates algorithm from Knuth TAOCP Vol. 2 Sec 3.4.2 | |
*/ | |
this.shuffle = function () { | |
var j = 52; | |
while (--j) { | |
var n = Math.random(); | |
var k = Math.floor(j * n) + 1; | |
var temp = this.cards[j]; | |
this.cards[j] = this.cards[k]; |
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
def match(regexp, text) | |
if (regexp.nil? or regexp.empty?) or (regexp[0..0] == '$' and text.empty?) then return true end | |
if regexp[0..0] == '^' then return match(regexp[1..regexp.size-1], text) end | |
if regexp[0..0] == '*' then return match(regexp[2..regexp.size-1], text[star(regexp[1..1], text)..text.size-1]) end | |
if text[0..0] == regexp[0..0] or regexp[0..0] == '.' then return match(regexp[1..regexp.size-1], text[1..text.size-1]) end | |
false | |
end | |
def star(char, text, count=0) | |
if char == text[0..0] |
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.writeln('hello world!'); // using the document object to directly write to the page | |
alert('hello world!'); // issuing an alert dialog box. | |
console.log('hello world!'); // writing to the browser console. |
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 sum(x, y) { | |
// antipattern: implied global | |
result = x + y; | |
return result; | |
} | |
function sum(x, y) { | |
var result = x + y; | |
return result; |
OlderNewer