Skip to content

Instantly share code, notes, and snippets.

View BolajiOlajide's full-sized avatar

Bolaji Olajide BolajiOlajide

View GitHub Profile
@ShirtlessKirk
ShirtlessKirk / luhn.js
Last active February 12, 2024 05:09
Luhn validation algorithm
/**
* Luhn algorithm in JavaScript: validate credit card number supplied as string of numbers
* @author ShirtlessKirk. Copyright (c) 2012.
* @license WTFPL (http://www.wtfpl.net/txt/copying)
*/
var luhnChk = (function (arr) {
return function (ccNum) {
var
len = ccNum.length,
bit = 1,
@afair
afair / bash.cheat
Created August 27, 2012 20:23
Bash Scripting Quick Reference
==========================================
BASH SCRIPTING ==========================================
========================================== TEST COMMAND
==========================================
Invoke: bash [options] file
Shebang: #!/usr/bin/env bash Test: test expression
In script: [ expression ]
========================================== Alternate: [[ espression ]]
LOOP Does not split string words
========================================== Does not expand pathglobs*
@jackiekazil
jackiekazil / rounding_decimals.md
Last active January 17, 2024 12:29
How do I round to 2 decimals in python?

How do I round to 2 decimals?

In python, you have floats and decimals that can be rounded. If you care about the accuracy of rounding, use decimal type. If you use floats, you will have issues with accuracy.

All the examples use demical types, except for the original value, which is automatically casted as a float.

To set the context of what we are working with, let's start with an original value.

Original Value

@jameslyons
jameslyons / caesarCipher.py
Last active February 10, 2022 19:53
Caesar Cipher Python
# we need 2 helper mappings, from letters to ints and the inverse
L2I = dict(zip("ABCDEFGHIJKLMNOPQRSTUVWXYZ",range(26)))
I2L = dict(zip(range(26),"ABCDEFGHIJKLMNOPQRSTUVWXYZ"))
key = 3
plaintext = "DEFEND THE EAST WALL OF THE CASTLE"
# encipher
ciphertext = ""
for c in plaintext.upper():
@staltz
staltz / introrx.md
Last active May 6, 2024 01:44
The introduction to Reactive Programming you've been missing
@PurpleBooth
PurpleBooth / README-Template.md
Last active May 6, 2024 07:22
A template to make good README.md

Project Title

One Paragraph of project description goes here

Getting Started

These instructions will get you a copy of the project up and running on your local machine for development and testing purposes. See deployment for notes on how to deploy the project on a live system.

Prerequisites

@lambdahands
lambdahands / _readme.md
Created September 28, 2015 17:09
FlowType and CSS Modules

Huh?

So basically FlowType doesn't know about CSS Modules, a really handy way of dealing with the plagues of CSS in codebases (global variables and dependency wackiness mainly).

What WebPack allows us to do is "require" CSS files and use their class names:

import styles from "my_styles.css";
import React from "react";
@AndrewJHart
AndrewJHart / jwt_authentication.py
Created April 13, 2016 18:47
JWT authentication middleware for django rest framework that populates the request.user object
from django.utils.functional import SimpleLazyObject
from django.contrib.auth.models import AnonymousUser
from rest_framework.request import Request
from rest_framework_jwt.authentication import JSONWebTokenAuthentication
def get_user_jwt(request):
"""
Replacement for django session auth get_user & auth.get_user for
@ivanleoncz
ivanleoncz / flask_app_logging.py
Last active May 23, 2021 07:25
Demonstration of logging feature for a Flask App.
#/usr/bin/python3
""" Demonstration of logging feature for a Flask App. """
from logging.handlers import RotatingFileHandler
from flask import Flask, request, jsonify
from time import strftime
__author__ = "@ivanleoncz"
import logging