Skip to content

Instantly share code, notes, and snippets.

Avatar

Nimrod Maina NimzyMaina

View GitHub Profile
View TempController.cs
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using TempConvert.Models;
using TempConvert.Interfaces;
using TempConvert.Repositories;
namespace TempConvert.Controllers
{
[Route("api/[controller]")]
[ApiController]
View TempConvertRepository.cs
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 Jun 8, 2020
Temp Convert Client Class
View TempConvertClient.cs
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 Jun 8, 2020
Consuming WSDL Services Using ASP.NET Core
View ITempConvert.cs
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 Feb 7, 2020
New and improved way to Identify Kenyan Phone Number Service provider
View service_providerV2.php
<?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 / virtual-env.md
Last active Dec 7, 2019
Creating a python virtual env with wrapper
View virtual-env.md

Creating a Virtual ENV in python

create env

mkvirtualenv createdenv

set project dir

@NimzyMaina
NimzyMaina / sms_placeholder_parser.php
Last active Dec 6, 2019
How to replace place holders in an SMS template in PHP
View sms_placeholder_parser.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 Sep 19, 2019
How to create decorators in python
View decorators.py
# 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!")
@NimzyMaina
NimzyMaina / virtual.sh
Created Sep 2, 2019
Virtual Env Commands
View virtual.sh
## Make virtual ENV
mkvirtualenv test
## Make virtual ENV in current DIR
mkvirtualenv -a $(pwd) test
## Make virtual ENV with Python version
mkvirtualenv -a $(pwd) python=python3 test
## Set project dir
View guzzleproxy.php
<?php
$http = new GuzzleHttp\Client;
$response = $http->post(url('oauth/token'), [
'form_params' => [
'grant_type' => 'password',
'client_id' => 2,
'client_secret' => 'SECRET_HERE',
'username' => 'user@example.com',