Skip to content

Instantly share code, notes, and snippets.

View BretCameron's full-sized avatar
🏠
Working from home

Bret Cameron BretCameron

🏠
Working from home
  • YuLife
  • London
View GitHub Profile
@BretCameron
BretCameron / package.json
Created June 21, 2019 10:48
A sample package.json file, as created by this custom npm init script: https://gist.github.com/BretCameron/24f0079bd2c546e704914b86f1b1627a
{
"name": "Custom npm init",
"version": "0.0.0",
"decription": "A test project, to demonstrate a custom npm init script.",
"main": "index.js",
"keywords": [],
"author": "Joe Bloggs <[email protected]> (joebloggs.com)",
"license": "ISC",
"repository": {
"type": "git",
@BretCameron
BretCameron / .npm-init.js
Created June 21, 2019 10:46
A custom npm init script, which incorporates an initial GitHub commit. The file should be in your home directory.
const { execSync } = require('child_process');
function run(func) {
console.log(execSync(func).toString())
}
module.exports = {
name: prompt('package name', basename || package.name),
version: prompt('version', '0.0.0'),
decription: prompt('description', ''),
@BretCameron
BretCameron / scraper.js
Last active June 20, 2019 09:33
A scraper that handles infinite scrolling
const scrapeNumber = 20;
const scrapeQuery = '.userContentWrapper';
const startTime = Date.now();
const lapseTime = 3600000; // that's 1 hour in milliseconds
let arrayOfItems = [];
let heightBefore = 0;
let heightAfter = 0;
while (arrayOfItems.length < scrapeNumber) {
await page.evaluate('window.scrollTo(0, document.body.scrollHeight)');
@BretCameron
BretCameron / Counter.js
Created June 19, 2019 16:59
A simple React counter component that uses Redux
import React, { Component } from 'react';
import { connect } from 'react-redux';
const containerStyle = {
display: 'flex'
}
const buttonStyle = {
fontSize: '1.5rem',
width: '40px',
height: '40px'
@BretCameron
BretCameron / package.json
Created June 14, 2019 11:13
main/package.json
{
"version": "1.0.0",
"description": "",
"main": "./src/index.js",
"scripts": {
"electron": "electron src",
"start": "cross-env NODE_ENV=dev nodemon --watch ./src/**/* --watch . --exec 'npm run electron'"
},
"keywords": [],
"author": "",
@BretCameron
BretCameron / index.js
Created June 14, 2019 10:47
main/src/index.js
const { app, BrowserWindow } = require('electron');
// Keep a global reference of the window object, if you don't, the window will
// be closed automatically when the JavaScript object is garbage collected.
let win;
function createWindow() {
win = new BrowserWindow({
width: 800,
height: 600,
@BretCameron
BretCameron / package.json
Created June 9, 2019 17:33
renderer/package.json
{
"name": "renderer",
"version": "0.1.0",
"private": true,
"dependencies": {
"react": "^16.8.6",
"react-dom": "^16.8.6",
"react-scripts": "3.0.1"
},
"scripts": {
@BretCameron
BretCameron / package.json
Last active June 14, 2019 11:04
desktop-app/package.json
{
"name": "desktop-app",
"version": "1.0.0",
"main": "index.js",
"scripts": {
"start": "concurrently \"(cd renderer && npm run start && cd ..)\" \"(cd main && npm run electron && cd ..)\""
},
"license": "ISC",
"devDependencies": {
"concurrently": "^4.1.0"
@BretCameron
BretCameron / index.js
Last active January 16, 2023 08:31
A variety of methods from the Google Drive and Google Sheets APIs
const { google } = require('googleapis');
const fs = require('fs');
const credentials = require('./credentials.json');
const scopes = [
'https://www.googleapis.com/auth/drive'
];
const auth = new google.auth.JWT(
@BretCameron
BretCameron / index.js
Created June 1, 2019 12:29
Use Node.js to get a list of files from Google Drive and save them locally
const { google } = require('googleapis');
const fs = require('fs');
const credentials = require('./credentials.json');
const scopes = [
'https://www.googleapis.com/auth/drive',
'https://www.googleapis.com/auth/spreadsheets',
];