Skip to content

Instantly share code, notes, and snippets.

:octocat:
Coding

Fay Vor phavor

:octocat:
Coding
View GitHub Profile
@phavor
phavor / currencies.js
Created Jan 28, 2020
List of Countries, currencies and code
View currencies.js
export const countries = [
{
code: "AE",
currency: "AED",
currencyName: "United Arab Emirates Dirham",
name: "United Arab Emirates"
},
{
code: "AF",
currency: "AFN",
@phavor
phavor / fly.js
Created Oct 21, 2019
Node script to spawn a new child process
View fly.js
const { spawn, exec } = require('child_process')
const drone = spawn('python', ['./src/controller/main.py'])
drone.stdout.pipe(process.stdout)
@phavor
phavor / main.py
Created Oct 21, 2019
main script to get the drone up and running
View main.py
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?']
@phavor
phavor / createPost.js
Created Oct 2, 2019
Create a new post
View createPost.js
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
) {
@phavor
phavor / useReducer.js
Created Oct 2, 2019
Add post using the useReducer
View useReducer.js
import React, { useReducer } from "react";
const AddPost = () => {
const [postState, setPostState] = useReducer(
(state, newState) => ({ ...state, ...newState }),
{
title: "",
body: ""
}
);
View AddPost.jsx
import React, { useQuery } from "react";
const AddPost = () => {
const [postState, setPostState] = useQuery({
title: "",
body: ""
});
const handleChange = e => {
setPostState({ [e.target.name]: e.target.value });
};
return (
@phavor
phavor / addUserToDB.js
Created Sep 21, 2019
Add users to our database...
View addUserToDB.js
const users = [
{
id: 1,
name: "Leanne Graham",
username: "Bret",
email: "Sincere@april.biz",
isActive: false,
address: {
street: "Kulas Light",
suite: "Apt. 556",
@phavor
phavor / cronMan.js
Last active Sep 21, 2019
Setup all the cron jobs needed by the application
View cronMan.js
const scheduler = require("./scheduler/scheduler");
const deleteInactives = require("./cron-jobs/deleteInactives");
// schedule the deleteInactive users job
scheduler(10000, deleteInactives);
@phavor
phavor / deleteInactives.js
Last active Sep 21, 2019
Deletes all inactive users from the DB
View deleteInactives.js
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";
@phavor
phavor / scheduler.js
Last active Sep 21, 2019
The scheduler fuction
View scheduler.js
const scheduler = (timer, action) => {
setInterval(action, timer)
}
process.nextTick(() => scheduler);
module.exports = scheduler
You can’t perform that action at this time.