Skip to content

Instantly share code, notes, and snippets.

View kn9ts's full-sized avatar
🌠
I am one with the force!

Eugene Mutai kn9ts

🌠
I am one with the force!
View GitHub Profile
@kn9ts
kn9ts / nairobijs-welcome-console-log.js
Created April 12, 2015 15:06
Nairobi JS welcome console log message
console.log('%cNairobi', 'background: #FFDE00; color: #555; font-weight: bolder; font-size: 50px; padding: 5px 40px; solid #FFDE00;');console.log('%cJS', 'background: #FFDE00; color: #555; font-weight: bolder; font-size: 200px; padding: 0px 25px; solid #FFDE00;')
@kn9ts
kn9ts / abacus-charts.directive.js
Created April 16, 2015 13:45
My 1st directive, was challenging, saving the neat tricks used in here, grabbing attribute data, and waiting for data from the servers and passing them to external function. Awesome angular!!
// ==================== Gainers Directive =======================
appEngine.directive('agCharts', function($chartDefaults) {
return {
restrict: 'E',
// <ag-charts chart-id="[[co_gain.id ]]" options="[[ co_gain.options ]]"></ag-charts>
scope: {
chartId: '@',
chartType: '@',
years: '@',
months: '@'
@kn9ts
kn9ts / index.html
Created April 27, 2015 09:55
html5 boilerplate
<!doctype html>
<html class="no-js" lang="">
<head>
<meta charset="utf-8">
<meta http-equiv="x-ua-compatible" content="ie=edge">
<title></title>
<meta name="description" content="">
<meta name="viewport" content="width=device-width, initial-scale=1">
@kn9ts
kn9ts / ObserverDP.html
Created April 28, 2015 08:49
Creating an observer with an observable pattern
<html>
<head>
<script language="javascript">
function ArrayList() {
this.aList = []; //initialize with an empty array
}
ArrayList.prototype.Count = function() {
return this.aList.length;
@kn9ts
kn9ts / object_inheritance_function.js
Created April 28, 2015 17:13
How jQuery's $.extend function works, a way for object to inherit other objects properties and functions
function extend(target_object) {
// Look for additional parameters in this function
// eg. extend(target_object, ....a,b,c,d)
if (!arguments[1]) {
return;
}
// If any extra arguments, which are objects
// loop through them
for (var index = 1; index < arguments.length; index++) {
@kn9ts
kn9ts / XHR.js
Created May 4, 2015 10:01
How to Make AJAX Requests With Raw Javascript
var xhr = new XMLHttpRequest();
xhr.onreadystatechange = isReady(function(xhr) {
console.log(xhr.responseText);
});
function isReady(callback) {
if (xhr.readyState < 4) {
return;
}
// ==UserScript==
// @name Use Markdown, sometimes, in your HTML.
// @author Paul Irish <http://paulirish.com/>
// @link http://git.io/data-markdown
// @match *
// ==/UserScript==
// If you're not using this as a userscript just delete from this line up. It's cool, homey.
@kn9ts
kn9ts / XMLHttpRequest.js
Created May 7, 2015 07:07
Making an ajax request using plain JavaScript
var data = {
ids: [12, 18, 27, 35, 41, 53, 66, 68, 72, 85, 94, 103, 111, 120, 133]
}
var xhr = new XMLHttpRequest();
xhr.onreadystatechange = function(xhr) {
if (xhr.readyState < 4 || xhr.status !== 200) {
return;
}
@kn9ts
kn9ts / interpolate.js
Last active August 29, 2015 14:20 — forked from cowboy/interpolate.js
// Uber-basic templating.. good? bad? ugly?
function interpolate( str, data ) {
data = data || window;
return !str
? ''
: str.replace( /{([^}]*)}/g, function(a,b){
return data[ b ] || '';
});
};
@kn9ts
kn9ts / tim.js
Last active August 29, 2015 14:20 — forked from bruntonspall/tim.js
/*
== Tim ==
A tiny JavaScript micro-templating script.
http://gist.github.com/521352
You can use Tim to write simple templates that use JavaScript's
familiar dot notation to replace template tags with JSON object
properties.