Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

View komuw's full-sized avatar

Komu Wairagu komuw

View GitHub Profile
@komuw
komuw / a_sqlite.go
Last active April 19, 2024 06:53
golang and sqlite
package main
import (
"context"
"database/sql"
"database/sql/driver"
"fmt"
"path"
"sync"
"sync/atomic"
@komuw
komuw / enable vt-x in chromebook
Last active April 11, 2024 23:33
How To enable VT-x support in chromebook
Generously taken from this discussion; https://github.com/dnschneid/crouton/issues/675
They've created a wiki: https://github.com/dnschneid/crouton/wiki/Repack-kernel-to-Enable-VT_x-for-Virtualbox
You should check it out to see if anything has changed.
A. first of all install virtualbox correctly: https://gist.github.com/komuW/10991598. then;
1.Open a shell on your Chrome OS
ie while in in chromeOS; open browser, then ctrl+alt+T, then type shell, then press enter
2.Disable verified boot :
@komuw
komuw / price_of_solar_panel.py
Last active February 29, 2024 11:18
price of solar
# How many units of KPLC do you use per month?
# Go to https://www.stimatracker.com/, click on `prepaid`, then enter amount in KES you use per month.
# Click `calculate`, it will give you your consumption in kwh. Mine is KES 5000, which give ~150kwh
monthly_kplc_cost = 5000 # KES
yearly_kplc_cost = monthly_kplc_cost * 12 # KES
consumption_per_month = 150 # kWh
consumption_per_month = 150 * 1000 # watt-hours
monthly_energy_production_of_solar_panel = (solar_panel_rating_in_watts * number_of_hrs_of_sunlight * solar_panel_efficiency_factor) * 30
@komuw
komuw / fixed_main_test.go
Last active February 20, 2024 14:34
It's hard to use gomock when there are goroutines involved. gomock sometimes expects them to be called and sometimes it doesn't
// file: main_test.go
package main
import (
"math/rand"
"sync"
"testing"
"time"
gomock "github.com/golang/mock/gomock"
@komuw
komuw / read_file.zig
Last active February 11, 2024 01:40
read a file in zig
const std = @import("std");
const os = std.os;
const warn = std.debug.warn;
pub fn main() !void {
var file = try os.File.openRead("/path/to/file.txt");
defer file.close();
const file_size = try file.getEndPos();
// why cant I use?
@komuw
komuw / fuzz_property_test.go
Last active January 19, 2024 11:03
Golang fuzz testing and also property-based testing.
package main
import (
"testing"
"pgregory.net/rapid"
)
// Sum adds two numbers.
func Sum(a, b int64) (total int64) {
@komuw
komuw / kenya_electricity_power.py
Last active December 15, 2023 20:11
kenya electricity power back of envelope stats
# These statistics, figures and projections are back of the envelope
# see; https://en.wikipedia.org/wiki/Back-of-the-envelope_calculation.
# Do not rely on them for serious matters.
# But they should mostly be relatively accurate.
import math
# According to EPRA(Energy and Petroleum Regulatory Authority)
# See: https://www.epra.go.ke/wp-content/uploads/2023/01/ABRIDGED-KPLC-TARIFF-2023.pdf
peak_demand_for_electricity_in_year_2020 = 1880 # megawatt. This was in july 2020
@komuw
komuw / create_vpn.sh
Last active November 15, 2023 09:12
create vpn
#https://www.zeitgeist.se/2013/11/22/strongswan-howto-create-your-own-vpn/
#https://www.gypthecat.com/ipsec-vpn-host-to-host-on-ubuntu-14-04-with-strongswan
#Example of simple pre-shared keys vpn setup: https://www.strongswan.org/uml/testresults/ikev2/rw-psk-ipv4/
$ sudo apt-get -y install strongswan
$ ipsec version
Linux strongSwan U5.1.2/K3.13.0-55-generic
Institute for Internet Technologies and Applications
University of Applied Sciences Rapperswil, Switzerland
See 'ipsec --copyright' for copyright information.
@komuw
komuw / hey.html
Created November 10, 2023 14:06
nested html table
<!DOCTYPE html>
<html>
<style>
table, th, td {
border:1px solid;
}
</style>
<body>
<h2>A basic HTML table</h2>
<table style="width:100%">