Skip to content

Instantly share code, notes, and snippets.

View k0d3d's full-sized avatar
🎯
Focusing

Rhema k0d3d

🎯
Focusing
View GitHub Profile
@k0d3d
k0d3d / prime.js
Last active April 19, 2019 10:45
Count Prime Number Arrays
function currentNumbers(s, marker) {
let range = new RegExp(`.{1,${marker}}`, 'g')
return s.match(range);
}
@k0d3d
k0d3d / Dockerfile
Created March 21, 2019 18:39
Change the exposed port as you see fit
FROM node:10-alpine
WORKDIR /home/node/app
COPY package*.json ./
RUN npm install
COPY . .
@k0d3d
k0d3d / strategies-index.js
Last active March 3, 2019 01:57
Mock stub startup for strategies
module.exports.isAwaitingReview = async function isAwaitingReview (context, page) {
return new Promise ((resolve, reject) => {
let currentUrl = await page.url()
if (currentUrl.indexOf('terms/unblock') > -1) {
const dialogButton = await page.$('[role=dialog]').$('button')
if (!dialogButton) {
return reject(page)
}
await dialogButton.click()
@k0d3d
k0d3d / utils-index.js
Created March 2, 2019 16:54
a simple function that always responds to requests
module.exports.returnResponse = async function returnResponse (context, page, status) {
context.res = {
status,
body: await page.content(),
headers: {
"Content-Type": "text/html",
"Current-Page_Url": await page.url()
}
};
return true
@k0d3d
k0d3d / index-9.js
Created March 2, 2019 16:53
using utils and strategy
const puppeteer = require("puppeteer");
const {returnResponse} = require('../utils')
module.exports = async function(context, req, pageCookiesIn) {
context.log("Started working function");
if (!req.body ||
!req.body.username ||
!req.body.password) {
context.res = {
status: 400,
@k0d3d
k0d3d / index-5.js
Created March 2, 2019 15:41
setting state data -> cookies now work using cosmos db bindings.
const puppeteer = require("puppeteer");
module.exports = async function(context, req, pageCookiesIn) {
context.log("Started working function");
if (!req.body ||
!req.body.username ||
!req.body.password) {
context.res = {
status: 400,
body: "Request Parameters not set // expecting {username: 'xxx', password: 'xxx'} in req.body"
@k0d3d
k0d3d / index-3.js
Created March 2, 2019 05:49
added output binding to function
const puppeteer = require("puppeteer");
module.exports = async function(context, req) {
context.log("Started working function");
if (!req.body ||
!req.body.username ||
!req.body.password) {
context.res = {
status: 400,
body: "Request Parameters not set // expecting {username: 'xxx', password: 'xxx'} in req.body"
@k0d3d
k0d3d / index-1.js
Last active February 25, 2019 13:04
deny if parameters and body is not set
const puppeteer = require("puppeteer");
module.exports = async function (context, req) {
context.log("Started working function");
if (!req.body ||
!req.body.username ||
!req.body.password) {
context.res = {
status: 400,
body: "Request Parameters not set // expecting {username: 'xxx', password: 'xxx'} in req.body"
@k0d3d
k0d3d / index.js
Created February 25, 2019 10:46
First browserless script
const puppeteer = require("puppeteer");
module.exports = async function(context, req) {
context.log("Started working function");
const browser = await puppeteer.connect({
browserWSEndpoint: "ws://d.ixit.com.ng"
});
const page = await browser.newPage();
@k0d3d
k0d3d / index.js
Last active February 11, 2019 12:05
Async function with nightmare
module.exports = async function (context, req) {
// keep ur module imports within
// this exported function
const Nightmare = require("nightmare");
const nightmare = Nightmare()
// @returns Promise
let n = nightmare
.goto('https://duckduckgo.com')