Skip to content

Instantly share code, notes, and snippets.

View jkirira's full-sized avatar

James Kirira jkirira

  • Nairobi, Kenya
View GitHub Profile
const randomElement = <T>(xs: T[]): T => {
const randomIndex = Math.floor(Math.random() * xs.length)
return xs[randomIndex]
}
// Example usage
const a = randomElement(['a', 'b', 'c'])
//The values in the array don't have to be the same type. Typescript can infer.
const b = randomElement([1, '2', 3, 4, {id: '1', foo: 'bar'}])

Add types when declaring or initializing.

let username: string = "jkirira"
let username: string;

Basic Types

let id: number = 5
let company: string = 'Traversy Media'
@jkirira
jkirira / Dockerfile
Last active October 17, 2024 15:32
Docker Ubuntu 22.04 Php* Composer
ARG COMPOSER_VERSION=2.2
#ARG COMPOSER_VERSION=latest
FROM composer:${COMPOSER_VERSION} AS composer
FROM ubuntu:22.04
ARG DEBIAN_FRONTEND=noninteractive
ARG PHP_VERSION=7.1
[
"Hello": "World",
"Como": [
"Estas": "Si",
"Esta": "Bien"
]
]
@jkirira
jkirira / login.spec.js
Last active February 11, 2023 19:36
Simple js testing spec for a vue login component
require('jsdom-global')()
const assert = require('assert')
import UserLogin from "../../../components/UserLogin";
import { mount } from '@vue/test-utils'
describe("login", () => {
let component;
const wrapper = mount(UserLogin)
@jkirira
jkirira / index.html
Last active March 2, 2022 10:18
Vue with plain css loader
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width,initial-scale=1.0" />
<title>codesandbox</title>
</head>
<body>