Skip to content

Instantly share code, notes, and snippets.

View wmucheru's full-sized avatar
💭
AI?

wmucheru

💭
AI?
  • Nairobi, Kenya
View GitHub Profile
@wmucheru
wmucheru / sort.js
Created October 26, 2022 12:25
Sort objects in array using boolean and string fields
const sortItems = () => {
const items = [
{
id: 1,
name: "Onion",
checked: true,
},
{
id: 2,
name: "Paper",
# Compound interest: https://www.youtube.com/watch?v=P182Abv3fOk
# A = P(1 + r/n)tN
def compound(principle, interest, time, annual = True):
interest_percent = interest / 100
amount_annual = principle * (1 + interest_percent) ** time
amount_monthly = principle * (1 + (interest_percent / 12)) ** (time * 12)
return amount_annual if annual else amount_monthly
@wmucheru
wmucheru / upload-preview.html
Created April 14, 2021 11:38
Upload and crop using CropperJS & VueJS
<link rel="stylesheet" href="cropper.min.css">
<div>
<div v-if="uploadError" class="alert alert-danger">{{ uploadError }}</div>
<label class="upload-label btn btn-sm btn-default">
Browse...
<input type="file" accept="image/*" v-on:change="previewCropUpload" multiple />
</label>
@wmucheru
wmucheru / angled-edge-pseudo-element-sass-mixin.markdown
Created November 26, 2019 11:34
Angled Edge Pseudo Element SASS Mixin
@wmucheru
wmucheru / DownloadActivity.java
Created September 6, 2018 13:19
Using DownloadManager to download files in Android
package app.test;
import android.app.Activity;
import android.app.DownloadManager;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.net.Uri;
import android.os.Bundle;
@wmucheru
wmucheru / form.html
Last active March 26, 2018 17:07
Send email with headers (Prevents going to spam)
<form class="form-horizontal col-md-10 cform" id="cform">
<div class="form-group">
<label class="control-label">Name*</label>
<input type="text" class="form-control" name="name" required />
</div>
<div class="form-group">
<label class="control-label">E-mail Address*</label>
<input type="email" class="form-control" name="email" required/>
</div>
<div class="form-group">
@wmucheru
wmucheru / acccessRedusStore.js
Created January 25, 2018 12:23
Accessing Redux Store outside a component
// tooling modules
import axios from 'axios'
// store
import store from '../store'
store.subscribe(listener);
function select(state) {
return state.auth.tokens.authentication_token
}
@wmucheru
wmucheru / countries.geo.json
Last active January 23, 2018 10:23
Leaflet Countries GeoJSON
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@wmucheru
wmucheru / geojson-filter.js
Last active January 23, 2018 10:13
Pick the property values from an existing GeoJSON, output as json string
let features = sourceJSON.features,
newFeatures = [];
features.map((feature, index) => {
let properties = feature.properties,
ft = {
geometry: feature.geometry,
properties: {
continent: properties.continent,
@wmucheru
wmucheru / soap-post.php
Created January 7, 2018 16:04
Make a Soap Request using PHP
function makeSOAPRequest($url, $soap_body){
$ch = curl_init();
curl_setopt( $ch, CURLOPT_URL, $url);
curl_setopt( $ch, CURLOPT_POST, true);
curl_setopt( $ch, CURLOPT_HTTPHEADER, array('Content-Type: text/xml'));
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt( $ch, CURLOPT_POSTFIELDS, $soap_body);
$result = curl_exec($ch);