Skip to content

Instantly share code, notes, and snippets.

@NjiruClinton
NjiruClinton / trie.go
Created April 4, 2025 20:40
Trie data structure in go
package trie
// TrieNode represents each node in the Trie
type TrieNode struct {
children map[rune]*TrieNode
isEnd bool
}
// Trie is the main data structure
type Trie struct {
@NjiruClinton
NjiruClinton / views.py
Last active January 29, 2024 11:54
django-rest-framework authentication (sign up, login)
from rest_framework.decorators import api_view, authentication_classes, permission_classes
from rest_framework.authentication import SessionAuthentication, TokenAuthentication
from rest_framework.permissions import IsAuthenticated
from rest_framework.response import Response
from rest_framework import status
from django.shortcuts import get_object_or_404
from django.contrib.auth.models import User
from rest_framework.authtoken.models import Token
@NjiruClinton
NjiruClinton / auth.dart
Created October 1, 2023 20:43
create users, sign in with email and password or google, sign out, send verification email and send email verification using firebase_auth and google_sign_in
import 'package:firebase_auth/firebase_auth.dart';
import 'package:google_sign_in/google_sign_in.dart';
class Auth{
final FirebaseAuth auth = FirebaseAuth.instance;
// create user with email and password
Future<User?> createUserWithEmailAndPassword({required String email, required String password}) async{
final UserCredential userCredential = await auth.createUserWithEmailAndPassword(email: email, password: password);
final User? user = userCredential.user;
return user;
@NjiruClinton
NjiruClinton / navigation.dart
Created September 16, 2023 19:14
bottom navigation bar flutter using google_nav_bar: ^5.0.6
import 'package:carpal/pages/account.dart';
import 'package:carpal/pages/hire.dart';
import 'package:carpal/pages/home.dart';
import 'package:carpal/pages/settings.dart';
import 'package:flutter/material.dart';
import 'package:google_nav_bar/google_nav_bar.dart';
void main() {
runApp(const MyApp());
}
@NjiruClinton
NjiruClinton / callback.php
Created July 1, 2023 21:51
mpesa-stk-push php
<?php
// in this file, the callback is request body is received from safaricom and saves the logs in a file. this response executes the querys inside the if statement. as simple as that! or was it..
include 'connection.php';
header("Content-Type: application/json");
$response = '{
"requestBodyReceived": 0,
"ResultDesc": "Confirmation Received Successfully"
}';
@NjiruClinton
NjiruClinton / mpesa-stk-push-expressjs.js
Last active May 8, 2023 23:16
mpesa stk-push for lipaNaMpesa online sandbox only, expressjs.
const express = require('express');
const app = express();
const bodyParser = require('body-parser');
const request = require('request');
app.use(bodyParser.json());
app.listen(3000, () => {
console.log('Server started on port 3000');
});