Skip to content

Instantly share code, notes, and snippets.

View kevinmungai's full-sized avatar

Kevin Mungai kevinmungai

View GitHub Profile
@kevinmungai
kevinmungai / sveltekit-tailwind-plugin.md
Last active April 5, 2024 07:59
How to add tailwind prettier plugin to sveltekit project with pnpm
  1. Install latest prettier and plugins
pnpm add -D prettier@latest prettier-plugin-svelte@latest prettier-plugin-tailwindcss@latest
  1. Change the default .prettierrc to prettier.config.js and replace with the following.
/** @type {import("prettier").Config} */
export default {
	useTabs: true,
@kevinmungai
kevinmungai / +layout.server.ts
Created September 1, 2023 21:05 — forked from ciscoheat/+layout.server.ts
Superforms with sveltekit-flash-message
export { load } from 'sveltekit-flash-message/server';

_layout.svelte

<script lang="ts">

import { onMount, setContext } from "svelte";
import { firebaseStore } from "../stores/firebase_store";
import {Child} from "../components/Child.svelte";

setContext("firebaseStore", firebaseStore);
@kevinmungai
kevinmungai / array-max.cpp
Created May 17, 2017 09:34
Finding the maximum value in an array
#include <iostream>
using namespace std;
int main() {
int i,n;
//float arr[100];
cout << "Enter total number of elements (1 to 100)"<< endl;
cin >> n;
@kevinmungai
kevinmungai / anki_algorithm.py
Created February 22, 2023 18:22 — forked from riceissa/anki_algorithm.py
my current understanding of Anki's spacing algorithm
"""
This is my understanding of the Anki scheduling algorithm, which I mostly
got from watching https://www.youtube.com/watch?v=lz60qTP2Gx0
and https://www.youtube.com/watch?v=1XaJjbCSXT0
and from reading
https://faqs.ankiweb.net/what-spaced-repetition-algorithm.html
There is also https://github.com/dae/anki/blob/master/anki/sched.py but I find
it really hard to understand.
Things I don't bother to implement here: the random fudge factor (that Anki
@kevinmungai
kevinmungai / MetricsUtil.kt
Created November 29, 2021 11:04 — forked from kevinhaitsma/MetricsUtil.kt
Convert dp to px and px to dp in Kotlin for Android
import android.content.Context
import android.content.res.Resources
import android.util.DisplayMetrics
/**
* Provides utilities for metrics.
*
* Original at:
* @see <a href="https://stackoverflow.com/a/9563438/8877070">stack overflow answer</a>
*
@kevinmungai
kevinmungai / initialization.sql
Created November 29, 2021 07:16 — forked from jbrown123/-Recursive Queries Using Common Table Expressions.md
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
(
@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 / 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 / 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>