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 / aws4_signing_using_get_query_params.py
Created December 3, 2016 20:22
This version makes a GET request and passes request parameters
# AWS Version 4 signing example
# IAM API (CreateUser)
# See: http://docs.aws.amazon.com/general/latest/gr/sigv4_signing.html
# This version makes a GET request and passes request parameters
# and authorization information in the query string
import sys, os, base64, datetime, hashlib, hmac, urllib
import requests # pip install requests
@kn9ts
kn9ts / aws4_signing.py
Last active March 4, 2023 06:19
AWS V4 signing example in python
# AWS Version 4 signing example
#
# Example:
# Authorization: AWS4-HMAC-SHA256 Credential=AKIDEXAMPLE/20150830/us-east-1/iam/aws4_request, SignedHeaders=content-type;host;x-amz-date, Signature=5d672d79c15b13162d9279b0855cfba6789a8edb4c82c400e06b5924a6f2b5d7
# Formulae:
# CanonicalRequest =
# HTTPRequestMethod + '\n' +
# CanonicalURI + '\n' +
# CanonicalQueryString + '\n' +
@kn9ts
kn9ts / restAPI.txt
Created November 22, 2016 21:25
Example of a REST API convention
GET /persons [All persons data in a list]
{
success: true,
response: [personObject, personObject, personObject, personObject...]
}
GET /persons/1575 [returns a single person]
{
success: true,
response: {
@kn9ts
kn9ts / why-unit-testing.md
Last active November 2, 2016 16:26
### Why Should We Unit Test?

Why Should We Unit Test?

When we develop applications the most important thing we can do is to ship code as fast and bug-free as possible. Testing helps us achieve those goals. The number one concern for developers who do not unit test is that it takes too long. When you're first getting into utilizing unit testing in development, it may take longer than you're used to. However, the long-term benefits far outweigh that initial investment, especially if we test before we write our application code. This is known as Test-driven Development (TDD).

Test-driven Development

We need to write a JavaScript function called isPrimary.

This function's main purpose is to return true if a number is a primary number and false if it's not.

@kn9ts
kn9ts / car.py
Last active November 1, 2016 22:29
An example of getting an attribute from a child class
class Car(object):
def __init__(self, model, engine, fuel_capacity, tires):
self.model = model
self.tires = tires
self.engine = engine
self.fuel_capacity = fuel_capacity
def drive(self, text):
print text + ' ' + self.model
@kn9ts
kn9ts / gist:bcc1c8730127bd9e5d50fa1a0880de07
Created October 23, 2016 11:21 — forked from illerucis/gist:4586359
Server-side Python + MongoDB + Flask implementation for DataTables
from collections import namedtuple
from pymongo import MongoClient
from flask import request
from core.web.site import app
from core.web.site.views_master import *
import json
'''
$('#companies').dataTable( {
"bProcessing": true,
@kn9ts
kn9ts / .eugene_aliases.bash
Created September 15, 2016 20:04
.eugene_mutai.bash
# alias hub (installed with brew to sugar up git) as git
alias git=hub
# sublime aliasing
alias sb=subl
# ln -s "/Applications/Sublime Text.app/Contents/SharedSupport/bin/subl" /usr/local/bin/subl
# other good aliases
alias sites='cd ~/Sites'
alias play="cd ~/Development/playground"
'use strict';
// import the file reader
const fs = require('fs');
class Index {
// method to read the json file
readJSONFromFile(filePath) {
this.books = JSON.parse(fs.readFileSync(filePath));
}
// catch 404 and forward to error handler
app.use((req, res, next) => {
const err = new Error('Not Found');
err.request = req.originalUrl;
err.status = 404;
next(err);
});
// error handlers
app.use((err, req, res) => {
@kn9ts
kn9ts / GPLv3.md
Last active March 8, 2024 07:26
GPLv3 explained

GPL3 LICENSE SYNOPSIS

TL;DR* Here's what the license entails:

1. Anyone can copy, modify and distribute this software.
2. You have to include the license and copyright notice with each and every distribution.
3. You can use this software privately.
4. You can use this software for commercial purposes.
5. If you dare build your business solely from this code, you risk open-sourcing the whole code base.