Skip to content

Instantly share code, notes, and snippets.

View wmucheru's full-sized avatar
💭
AI?

wmucheru

💭
AI?
View GitHub Profile
@wmucheru
wmucheru / TagsInput.jsx
Last active May 9, 2019 12:36
React Tags Input component. Used in multiple emails/tags entry
import React, { Component } from 'react';
export default class TagsInput extends Component{
constructor(props){
super(props);
this.state = {
tags: []
};
@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);
@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 / countries.geo.json
Last active January 23, 2018 10:23
Leaflet Countries GeoJSON
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@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 / 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 / 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 / angled-edge-pseudo-element-sass-mixin.markdown
Created November 26, 2019 11:34
Angled Edge Pseudo Element SASS Mixin
@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>
# 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