Skip to content

Instantly share code, notes, and snippets.

View Billcountry's full-sized avatar
👻
Busy participating in a historic event.

Billcountry Mwaniki Billcountry

👻
Busy participating in a historic event.
View GitHub Profile
@Billcountry
Billcountry / server.go
Last active November 12, 2020 15:14
Demo code to write logs to alt4.dev using gin gonic
package main
import (
"fmt"
"github.com/alt4dev/go/log"
"github.com/gin-gonic/gin"
)
func loggingMiddleWare(ctx *gin.Context) {
// Start a log group and defer it's close at the end of the request
defer log.Claims{
@Billcountry
Billcountry / dict_tools.py
Last active April 6, 2020 04:09
An improvement over built in dictionary allowing you to access values using a `dot` notation.
import json
class Dict(dict):
def __init__(self, **kwargs):
super(Dict, self).__init__()
for key, value in kwargs.items():
self[key] = value # Takes advantage of __setitem__ logic
def __json__(self):
@Billcountry
Billcountry / images.js
Last active February 4, 2018 11:34
Load images after the whole page has loaded by just adding the class .async-img
// Default image data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mO8dPv2fwAImAOJMh4kwgAAAABJRU5ErkJggg==
function load_images(){
var images = document.querySelectorAll(".async-img");
for(var id=0; id<images.length; id++){
var image = images[id];
var img_url = image.getAttribute('url');
image.src = img_url;
}
@Billcountry
Billcountry / deploy.php
Last active February 3, 2018 15:49
This file will deploy your git repository to a php server or the directory it's. It's convenient for cpanel hosting and you can add it's URL as a web-hook so that it's updated every time you push your updates to git.
<?php
ini_set('display_errors', 1);
header('Content-Type: text/plain');
$account = '_YOUR_ACCOUNT_NAME_'; // Example Billcountry
$repo = '_REPO_TO_DEPLOY_'; // iF i NEED TO EXPLAIN THIS YOU SHOULD PROBABLY LEAVE
$branch = '_BRANCH_TO_DEPLOY_';
$url = "https://github.com/$account/$repo/archive/$branch.zip";
echo("Cloning into $url\n");
$path = dirname(__FILE__)."/$branch.zip";
@Billcountry
Billcountry / utilities.py
Created November 8, 2017 03:44
A collection of functions that I use to speed up my productivity. Feel free to use them as you wish. Connect's to a database, provides method to insert table, run sql queries, hash using sha256, generate dates with addation or removal of time, log your errors among others
import smtplib
import os
import random
import hashlib
from datetime import datetime
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
from validate_email import validate_email
import sqlalchemy
from sqlalchemy import engine
@Billcountry
Billcountry / LICENSE.md
Last active October 4, 2022 05:56
A wrapper for fetch that falls back to Jquery ajax if the fetch api is not available on the browser.

Copyright 2022 Billcountry

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER

@Billcountry
Billcountry / proxy.py
Last active September 29, 2017 03:29
An easy way to create personal proxy servers and bouncing your connection off several servers before the connection finally reaches you. Use with caution, am not responsible of your actions.
#!/usr/bin/python
import sys, thread, socket
'''
Under MIT License
To run Simply
(If you make proxy.py executable)
./proxy.py 8090
(Else)
python proxy.py 8090