Skip to content

Instantly share code, notes, and snippets.

View gabeno's full-sized avatar
🎯
Focusing

Gabriel Majivu gabeno

🎯
Focusing
View GitHub Profile
@gabeno
gabeno / tic-tac-toe
Created August 1, 2013 23:22
A simple game of tic-tac-toe written in JavaScript - practice
/*
* program for tic-tac-toe game
* it starts with a randomly placed X
*/
var ticTacToe = {
// board layout
board: [],
@gabeno
gabeno / FizzBuzz
Last active December 20, 2015 13:09
FizzBuzz Program in JS
for (var i = 1; i <= 100; i++){
if (i % 15 == 0) {
console.log('FizzBuzz')
} else if (i % 3 == 0) {
console.log('Fizz')
} else if (i % 5 == 0) {
console.log('Buzz')
} else {
console.log(i)
}
@gabeno
gabeno / blog-array-index
Created August 13, 2013 10:20
Code snippet for blog entry: Array Index versus Object Property Name
var a = [];
a['0'] = 1; // assign value using property name as string
// number converted to string and used as property name
a[1] = 2; // assign value using property as an integer
a[2.0] = 3; // assign value using property as a floating point number
console.log(a) // => [1,2,3]
console.log(a.length) // => 3
@gabeno
gabeno / closures-js
Created October 29, 2013 10:15
A simple way to understand closures...
// a simple function to display a greeting
var sayHello = function() {
return alert('Hello there!');
};
sayHello(); // => Hi there!
// ----------------------------------------
// function returns an object, text preset
@gabeno
gabeno / ymail-imap-res
Last active January 1, 2016 12:29
mail object for ymail
// Message #333
{ html: '...',
text: '...',
headers:
{ 'x-apparently-to': '<email_address>@yahoo.com via 98.138.31.140; Thu, 19 Dec 2013 16:50:09 +0000',
'return-path': '<t0058a35c69-e0cd9af96-c48313d748aa4f5085b042a35ccd1cdf@bounce.twitter.com>',
'received-spf': 'pass (domain of bounce.twitter.com designates 199.16.156.159 as permitted sender)',
'x-ymailisg': 'HUq.WUwWLDt6lAQnXg3wAfGN1o6LPrWrzivGCVzzcqdNHaR8 KjFr5XCUy_4_pGxLJIYCJ2MahDvriOUhWUwZk3CvuA1xC6i.eU7gMr20R0pa TVY9cHUiqC.1K3F8hxrbm2nEakr0lmjkkCDkUqYoA0zynO_0jKIJLN0cXrmK LF1vXaa_1637dgYnuOOTN_d4QBh8xZ3iEkmUwJDPYkZp8bHz0aV7BAhfJ5Qe ygkJZPayB5eILh.4gsNxvMOYnESrIvUxa3dgDheBP7TUeZHcbPTdsvqx3SG5 sKuzRId2FzHvoyCcT.RM2EZyQ6gbnZfL_pXnopAHz_tyvkch_Wz5pR.PwaGG bzI28orN40hDz_29F311O5tZjwJGBySwnu_H807Bnmq_KitbhnpC3cEcZydS 2L5cUU9b9eIY.f_UrSjhPVRM_mNCou7qeWrq9n0VMz3wFc35BGaGyheB.Sii JIUXrzui6JYyxXlW1Evx7JIezIp1j7Thmgm7XqIvWnQe8.LjnMt8NCYXWsl3 O.3bb88GF5gBMt4XvkgZIWVhjOlnIFjktHbgyUbNgbig1AevO2tNGIrd4w5L KNH4q8uOzFTBK7dejVGJ4i6XY6Z8OqoX15GCvmH
@gabeno
gabeno / gmail-imap-res
Created December 27, 2013 11:00
mail object for gmail
{ html: '...',
text: '...',
headers:
{ 'delivered-to': '[email protected]',
received:
[ 'by 10.76.90.165 with SMTP id bx5csp523526oab; Fri, 27 Dec 2013 02:41:07 -0800 (PST)',
'by 10.194.122.169 with HTTP; Fri, 27 Dec 2013 02:40:46 -0800 (PST)' ],
'return-path': '<[email protected]>',
'received-spf': 'pass (google.com: domain of [email protected] designates 10.180.20.15 as permitted sender) client-ip=10.180.20.15',
'authentication-results': 'mr.google.com; spf=pass (google.com: domain of [email protected] designates 10.180.20.15 as permitted sender) [email protected]; dkim=pass [email protected]',
@gabeno
gabeno / random_string
Last active January 2, 2016 22:39
Random String of n characters
function randomString(n) {
var str = "";
for (var i=0; i<n; i++) {
str += String.fromCharCode(Math.floor(Math.random()*26 + 97))
}
return str;
}
randomString(5) // => "xkcdy"
randomString(7) // => "idhmtus"
@gabeno
gabeno / jsdom-node
Created February 12, 2014 05:41
setting up jsdom in nodejs for headless testing
'use strict';
var expect = require('chai').expect;
var jsdom = require('jsdom');
var jquery = require('jquery'); // option 2
var TodoView = require('../hello-backbone/views/todo-view');
describe('Backbone.View', function() {
var $, todoView; // option 1
@gabeno
gabeno / backbone-events
Created February 13, 2014 11:01
remove callback bug in backbone?
'use strict';
var chai = require('chai'),
expect = chai.expect,
sinon = require('sinon'),
sinonChai = require('sinon-chai');
var Backbone = require('backbone');
var _ = require('lodash/dist/lodash.underscore');
@gabeno
gabeno / assignment operator
Created March 8, 2014 14:50
Deduce meaning of assignment operator |=
a = new Array();
for (var b = 0; b < 10; b++) {
a[0] |= b; // <= ?
}