Skip to content

Instantly share code, notes, and snippets.

View kayode-adechinan's full-sized avatar

Kayode Adechinan kayode-adechinan

  • Dakar, Senegal
View GitHub Profile
@kayode-adechinan
kayode-adechinan / django-cheat-sheet.md
Last active March 26, 2020 11:00
Django Cheat Sheet

Random string - random username

from django.utils.crypto import get_random_string
User.objects.create_user(username=get_random_string(), email='', password='123')

Build API

install

@kayode-adechinan
kayode-adechinan / cheat-sheet-angular.md
Last active January 17, 2020 17:18
Angular Cheat Sheet

if

<div *ngIf="condition; else elseBlock">Content to render when condition is true.</div>
<ng-template #elseBlock>Content to render when condition is false.</ng-template>

ngFor

<ul>
    <li *ngFor="let element of array"></li>
input, textarea {
outline: none;
border:1px solid #ccc !important;
box-shadow:none !important;
}
@kayode-adechinan
kayode-adechinan / reactjs_quickstart
Created December 1, 2019 12:22
reactjs_quickstart
import React, { Component } from "react";
import axios from "axios";
class Row extends React.Component {
render() {
return (
<tr>
<td>{this.props.data.id}</td>
<td>{this.props.data.name}</td>
</tr>
@kayode-adechinan
kayode-adechinan / java8-one-liners-for-statistical-properties.md
Created October 26, 2019 23:58 — forked from asela38/java8-one-liners-for-statistical-properties.md
Java 8 One liners for statistical properties : Mean, Mode, Median(Q2), Q1, Q2, Variance, Standard Deviation

While working on a Hacker Rank Problem I wrote few one lines using java stream to find mean, median, mode, Q1, Q3, variance and standard deviation. Thought to share since it's quite interesting.

        // mean
        double mean = list.stream().mapToInt(Integer::intValue).average().getAsDouble();
        System.out.println(mean);
        
        // mode - create count map using group by and sorted with custom comparator to give minimum from competing probable mode values
        Integer mode = list.stream()
                .collect(Collectors.groupingBy(i -> i, () -> new TreeMap<Integer, Long>(), Collectors.counting()))
@kayode-adechinan
kayode-adechinan / upload-a-file.MD
Created August 21, 2019 10:04 — forked from ahmadawais/upload-a-file.MD
Upload a file using the WordPress REST API

Upload files

Using the REST API to upload a file to WordPress is quite simple. All you need is to send the file in a POST-Request to the wp/v2/media route.

There are two ways of sending a file. The first method simply sends the file in the body of the request. The following PHP script shows the basic principle:

@kayode-adechinan
kayode-adechinan / docker-compose.yml_django
Created August 6, 2019 17:19
simple docker-compose for django
version: '3.7'
services:
db:
image: postgres:10.1-alpine
volumes:
- postgres_data:/var/lib/postgresql/data/
web:
build: .
command: python manage.py runserver 0.0.0.0:8000
@kayode-adechinan
kayode-adechinan / Dockerfile_django
Created August 6, 2019 17:18
Simple dockerfile for django
# Pull base image
FROM python:3.7-slim
# Set environment varibles
ENV PYTHONDONTWRITEBYTECODE 1
ENV PYTHONUNBUFFERED 1
# Set work directory
WORKDIR /code
version: "3"
services:
elasticsearch:
image: docker.elastic.co/elasticsearch/elasticsearch-oss:6.2.3
environment:
discovery.type: single-node
volumes:
- elastic-data:/usr/share/elasticsearch/data
ports:
@kayode-adechinan
kayode-adechinan / geo.js
Created August 5, 2019 10:28 — forked from mkhatib/geo.js
A Javascript utility function to generate number of random Geolocations around a center location and in a defined radius.
/**
* Generates number of random geolocation points given a center and a radius.
* @param {Object} center A JS object with lat and lng attributes.
* @param {number} radius Radius in meters.
* @param {number} count Number of points to generate.
* @return {array} Array of Objects with lat and lng attributes.
*/
function generateRandomPoints(center, radius, count) {
var points = [];
for (var i=0; i<count; i++) {