Skip to content

Instantly share code, notes, and snippets.

View emkay's full-sized avatar

Michael Matuzak emkay

View GitHub Profile
YUI().use('node', 'gallery-yql', function (Y) {
new Y.yql('select * from github.user.repos where id = "emkay"', function (r) {
// do something with r
});
});
<script src="http://yui.yahooapis.com/3.2.0/build/yui/yui-min.js"></script>
<div id="twitter-feed-title" style="display:none;">
<div id="twitter-feed">
</div>
</div>
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>');
}
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.build = function () {
for (i = 1; i <= 4; i++) {
for (j = 1; j <= 13; j++) {
this.cards.push(new Card(j, this.suits[i]));
}
}
};
/*
* 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];
@emkay
emkay / gist:1291402
Created October 16, 2011 20:47
Ruby regex matcher
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]
@emkay
emkay / hello.js
Created November 8, 2011 02:20
Javascript hello world
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.
@emkay
emkay / global-antipattern.js
Created November 8, 2011 04:52
global antipattern
function sum(x, y) {
// antipattern: implied global
result = x + y;
return result;
}
function sum(x, y) {
var result = x + y;
return result;