Skip to content

Instantly share code, notes, and snippets.

View NimzyMaina's full-sized avatar

Nimrod Maina NimzyMaina

View GitHub Profile
@NimzyMaina
NimzyMaina / kra_pin_regex.php
Last active November 22, 2023 08:31
Regex to validate KRA PIN
<?php
$kra_regex = "/^[A]{1}[0-9]{9}[a-zA-Z]{1}$/";
$kra_pin = "A001234567J";
if(preg_match($kra_regex, $kra_pin)){
echo "Success! Valid KRA PIN";
}
else{
echo "Error! Invalid KRA PIN";
}
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using TempConvert.Models;
using TempConvert.Interfaces;
using TempConvert.Repositories;
namespace TempConvert.Controllers
{
[Route("api/[controller]")]
[ApiController]
@NimzyMaina
NimzyMaina / TempConvertRepository.cs
Created June 8, 2020 10:38
Temp Convert Repository
using System;
using System.ServiceModel;
using System.Threading.Tasks;
using System.Xml;
using Microsoft.Extensions.Options;
using TempConvert.Models;
using TempConvert.Interfaces;
namespace TempConvert.Repositories
{
@NimzyMaina
NimzyMaina / TempConvertClient.cs
Created June 8, 2020 10:19
Temp Convert Client Class
using System;
using System.ServiceModel;
using System.ServiceModel.Channels;
using System.ServiceModel.Description;
using System.Threading.Tasks;
using System.Xml;
using TempConvert.Interfaces;
namespace TempConvert.Clients
{
@NimzyMaina
NimzyMaina / ITempConvert.cs
Last active June 8, 2020 10:13
Consuming WSDL Services Using ASP.NET Core
using System.Threading.Tasks;
namespace TempConvert.Interfaces
{
[System.ServiceModel.ServiceContractAttribute(
Namespace="https://www.w3schools.com/xml/",
ConfigurationName="TempConvert.Interfaces.ITempConvert")]
public interface ITempConvert
{
@NimzyMaina
NimzyMaina / service_providerV2.php
Last active February 7, 2020 11:57
New and improved way to Identify Kenyan Phone Number Service provider
<?php
// Gotten from https://en.wikipedia.org/wiki/Telephone_numbers_in_Kenya#Mobile_phone_numbers
$providers = [
'100' => 'Airtel',
'101' => 'Airtel',
'102' => 'Airtel',
'110' => 'Safaricom',
'111' => 'Safaricom',
'701' => 'Safaricom',
@NimzyMaina
NimzyMaina / service_provider.php
Last active February 3, 2020 10:07
Kenya Identify Network Service Provider
<?php
$phone = "0748123456"; // safaricom
//$phone = "+254789123456"; // airtel
$safaricom = "/(+?254|0|^){1}[-. ]?[7]{1}([0-2]{1}[0-9]{1}|[5|9]{1}[0-9]{1}|[4]{1}[0-4]{1}|[4]{1}[6|8]{1})[0-9]{6}z/";
$equitel = "/(\+?254|0|^){1}[-. ]?[7]{1}([6]{1}[3-5]{1})[0-9]{6}\z/";
$airtel = "/(\+?254|0|^){1}[-. ]?[7]{1}([3]{1}[0-9]{1}|[5]{1}[0-6]{1}|[8]{1}[0-2|5-9]{1})[0-9]{6}\z/";
$telcom = "/(\+?254|0|^){1}[-. ]?[7]{1}([7]{1}[0-9]{1})[0-9]{6}\z/";
if(preg_match($safaricom, $phone)){
echo 'SAFARICOM';
@NimzyMaina
NimzyMaina / virtual-env.md
Last active December 7, 2019 16:51
Creating a python virtual env with wrapper

Creating a Virtual ENV in python

create env

mkvirtualenv createdenv

set project dir

@NimzyMaina
NimzyMaina / sms_placeholder_parser.php
Last active December 6, 2019 15:03
How to replace place holders in an SMS template in PHP
<?php
$msg = 'Dear {{BNAME}}, your loan of KES {{AMOUNT}} has been fully repaid.';
function wrap($str)
{
return "{{{$str}}}";
}
function parse($msg,array $placeholders)
@NimzyMaina
NimzyMaina / decorators.py
Created September 19, 2019 11:40
How to create decorators in python
# A decorator is just a function that gets called before another function
import functools # function tools
def my_decorator(f):
@functools.wraps(f)
def function_that_runs_f():
print("Hello!")
f()
print("After!")