Skip to content

Instantly share code, notes, and snippets.

View kevinmungai's full-sized avatar

Kevin Mungai kevinmungai

View GitHub Profile
@kevinmungai
kevinmungai / fsm_ussd.clj
Created September 11, 2019 15:41
finite state machine - ussd
(ns ussd.fsm-utils
(:require
[clojure.string :as str]
[clojure.edn :as edn]
[ussd.sms :as sms]))
(defn check-via
[via]
(let [choices (:choices (edn/read-string (slurp "../../ussd_fsm.edn")))]
(if (contains? choices via)
@kevinmungai
kevinmungai / file_io.clj
Created September 12, 2019 14:11 — forked from mfikes/file_io.clj
Async file io in Clojure
(ns api-server.file-io
(:use [clojure.tools.logging :only (info warn error)])
(:import (java.nio.channels CompletionHandler AsynchronousFileChannel)
(java.nio ByteBuffer)
(java.nio.file.attribute FileAttribute)
(java.nio.file StandardOpenOption)
(java.util.concurrent Executors))
(:require [clojure.core.async :as async :refer [chan go put! close!]]
[clojure.java.io :as io]))
@kevinmungai
kevinmungai / main.dart
Created January 1, 2020 23:25 — forked from felangel/main.dart
Bloc with SearchDelegate
import 'dart:async';
import 'package:flutter/material.dart';
import 'package:bloc/bloc.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
@kevinmungai
kevinmungai / web-component-v1.cljs
Created April 3, 2020 15:02 — forked from thheller/web-component-v1.cljs
create web-component v1 in cljs without class
(defn component []
(js/Reflect.construct js/HTMLElement #js [] component))
(set! (.-prototype component)
(js/Object.create (.-prototype js/HTMLElement)
#js {:connectedCallback
#js {:configurable true
:value
(fn []
(this-as this
@kevinmungai
kevinmungai / CurrencyPtBrInputFormatter.dart
Created December 4, 2020 07:51 — forked from andre-bahia/CurrencyPtBrInputFormatter.dart
Flutter TextInputFormatter Currency pt_BR
import 'package:flutter/services.dart';
import 'package:intl/intl.dart';
class CurrencyPtBrInputFormatter extends TextInputFormatter {
TextEditingValue formatEditUpdate(TextEditingValue oldValue, TextEditingValue newValue) {
if(newValue.selection.baseOffset == 0){
return newValue;
}
@kevinmungai
kevinmungai / sapper_with_firebase_hosting.md
Created December 27, 2020 07:15
Sapper with Firebase Hosting
  1. Create Directory for your app mkdir my-app
  2. get the sapper template npx degit "sveltejs/sapper-template#rollup"
  3. Install the packages npm i
  4. Install express server npm i express
  5. Initialize Firebase firebase init
@kevinmungai
kevinmungai / using_shadow_cljs_with_react_native.md
Created June 16, 2019 09:04
Using Shadow CLJS with React Native

How to use Shadow CLJS with React Native

This guides does not assume you are using expo. It is not yet perfect, especially the hot reloading part but maybe shadow-cljs could be modified.

  1. Create the React Native Project
react-native init <NameOfYourProject>
@kevinmungai
kevinmungai / idb.js
Created June 3, 2021 10:29 — forked from TalAter/idb.js
IndexedDB upgrade code to add index to an existing object store
request.onupgradeneeded = function(event) {
var db = event.target.result;
var upgradeTransaction = event.target.transaction;
var objectStore;
if (!db.objectStoreNames.contains("my-store")) {
objectStore = db.createObjectStore("my-store");
} else {
objectStore = upgradeTransaction.objectStore('my-store');
}
@kevinmungai
kevinmungai / diamondPattern.cpp
Created October 10, 2017 09:57
Diamond Pattern Using OpenGL in C++
/*
The Code Below is used to develop a Diamond Pattern.
1. Start with Identifying the First Diamond
2. Put in the coordinates for the First Diamind
3. Create a for-loop to to create diamonds at the same time
4. Introduce an outer for-loop to cater for the y - axis.
*/
@kevinmungai
kevinmungai / initialization.sql
Created November 29, 2021 07:16 — forked from jbrown123/initialization.sql
Creating arbitrary-depth recursive queries in SQLITE (works for any SQL compliant system) using CTEs (common table expressions)
DROP TABLE IF EXISTS users;
DROP VIEW IF EXISTS bp;
CREATE TABLE users (name, cn, title, manager);
CREATE VIEW bp AS
-- create a CTE (common table expression)
-- think of this as creating a temporary table that only exists during this query
-- works somewhat like CREATE TEMPORARY TABLE bosspath(cn, path)
WITH RECURSIVE bosspath(cn,path) AS
(