Skip to content

Instantly share code, notes, and snippets.

View emkay's full-sized avatar

Michael Matuzak emkay

View GitHub Profile
function willNotInline() {
/*
--------------------------------------------------------------------------
--------------------------------------------------------------------------
--------------------------------------------------------------------------
--------------------------------------------------------------------------
--------------------------------------------------------------------------
--------------------------------------------------------------------------
--------------------------------------------------------------------------
--------------------------------------------------------------------------
@emkay
emkay / not-bach.js
Created April 23, 2015 20:23
Not Bach
var Song = require('nesly-sound');
var song = Song();
var sq1 = song.square1;
var sq2 = song.square2;
var tri = song.triangle;
var noi = song.noise;
var Aminor4 = ['A4', 'C4', 'E4', 'A5'];
var Cmajor3 = ['C3', 'E3', 'G3', 'C4'];
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]