from django.utils.crypto import get_random_string
User.objects.create_user(username=get_random_string(), email='', password='123')
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
input, textarea { | |
outline: none; | |
border:1px solid #ccc !important; | |
box-shadow:none !important; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
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()))
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:
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Pull base image | |
FROM python:3.7-slim | |
# Set environment varibles | |
ENV PYTHONDONTWRITEBYTECODE 1 | |
ENV PYTHONUNBUFFERED 1 | |
# Set work directory | |
WORKDIR /code |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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++) { |