Skip to content

Instantly share code, notes, and snippets.

View cziem's full-sized avatar
:octocat:
Coding

Favour George C cziem

:octocat:
Coding
View GitHub Profile
@cziem
cziem / main.py
Created October 21, 2019 10:56
main script to get the drone up and running
from src.controller.services.delays import command_delays as delays
from src.controller.services.drone_services import Drone
from time import sleep
import sys
'''
'takeoff', 'land', 'time?', 'speed?',
'''
command_list = ['command', 'battery?']
@cziem
cziem / createPost.js
Created October 2, 2019 14:46
Create a new post
import React, { useReducer } from "react";
import { useMutation } from "@apollo/react-hooks";
const AddPost = () => {
const ADD_POST = gql`
mutation(
$authorId: ID!
$title: String!
$body: String
$isPublished: Boolean
) {
@cziem
cziem / useReducer.js
Created October 2, 2019 14:44
Add post using the useReducer
import React, { useReducer } from "react";
const AddPost = () => {
const [postState, setPostState] = useReducer(
(state, newState) => ({ ...state, ...newState }),
{
title: "",
body: ""
}
);
@cziem
cziem / AddPost.jsx
Created October 2, 2019 14:41
Add a new post
import React, { useQuery } from "react";
const AddPost = () => {
const [postState, setPostState] = useQuery({
title: "",
body: ""
});
const handleChange = e => {
setPostState({ [e.target.name]: e.target.value });
};
return (
@cziem
cziem / addUserToDB.js
Created September 21, 2019 13:30
Add users to our database...
const users = [
{
id: 1,
name: "Leanne Graham",
username: "Bret",
email: "Sincere@april.biz",
isActive: false,
address: {
street: "Kulas Light",
suite: "Apt. 556",
@cziem
cziem / cronMan.js
Last active September 21, 2019 12:17
Setup all the cron jobs needed by the application
const scheduler = require("./scheduler/scheduler");
const deleteInactives = require("./cron-jobs/deleteInactives");
// schedule the deleteInactive users job
scheduler(10000, deleteInactives);
@cziem
cziem / deleteInactives.js
Last active September 21, 2019 12:03
Deletes all inactive users from the DB
const User = require("../../models/user.schema");
const deleteInactives = async () => {
const deletedUsers = await User.deleteMany({ isActive: false });
if (deletedUsers.ok === 1) {
let verb = deletedUsers.n > 1 ? "users" : "user";
console.log(`${deletedUsers.deletedCount} Inactive ${verb} deleted`);
} else {
return "Error deleting users";
@cziem
cziem / scheduler.js
Last active September 21, 2019 11:43
The scheduler fuction
const scheduler = (timer, action) => {
setInterval(action, timer)
}
process.nextTick(() => scheduler);
module.exports = scheduler
@cziem
cziem / index.js
Created September 21, 2019 09:47
Setup the an express server
const express = require("express");
const mongoose = require("mongoose");
const port = process.env.PORT || 4000;
const uri = process.env.MONGODB_URI;
const options = {
useCreateIndex: true,
useNewUrlParser: true,
useFindAndModify: false,
@cziem
cziem / config.json
Created September 6, 2019 21:05
configuration example values
{
"test": {
"SECRET_KEY": "yOUrsEkretKey",
"MONGODB_URI_OFFLINE": "mongodb://localhost:27017/goals",
"PORT": 4400,
"SALT_ROUND": 15,
"BASE_URL": "http://localhost:3000",
"SSL_PORT": 4040,
"SENDER_EMAIL": "sales@goals-now.com",
"SENDER_PASS": "21b-19f318b0",