Skip to content

Instantly share code, notes, and snippets.

View Uvacoder's full-sized avatar

uvacoder Uvacoder

View GitHub Profile
@Uvacoder
Uvacoder / add-user-to-private-repo.js
Created January 2, 2022 01:47 — forked from DavidWells/add-user-to-private-repo.js
Add GitHub user to private GitHub repo utility function
const axios = require('axios')
const GITHUB_REPO = process.env.GITHUB_REPO
const GITHUB_API_TOKEN = process.env.GITHUB_API_TOKEN
const GITHUB_USERNAME = process.env.GITHUB_USERNAME
module.exports = function addUserToGithubRepo(username) {
const githubEndpoint = `https://api.github.com/repos/${GITHUB_REPO}/collaborators/${username}`
const config = {
'headers': {
'User-Agent': GITHUB_USERNAME,
@Uvacoder
Uvacoder / auto-install-npm-deps.js
Created January 2, 2022 01:47 — forked from DavidWells/auto-install-npm-deps.js
Automatically install deps for any serverless project found
const path = require('path')
const globby = require('globby')
const execSync = require('child_process').execSync
globby(['*/serverless.yml']).then(paths => {
// Now run npm install
const command = `npm install`
paths.forEach((p) => {
var t = path.join(__dirname, p)
execSync(command, {
const CHARS = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!@#$%^&*()_+-={}[]:;<>?/|\\';
function generatePassword(length = 12) {
let pass = '';
for (let i = length; i > 0; --i) pass += CHARS[Math.floor(Math.random() * CHARS.length)];
return pass
}
// Usage:
generatePassword(15)
@Uvacoder
Uvacoder / string-to-boolean.js
Created January 2, 2022 01:48 — forked from DavidWells/string-to-boolean.js
Convert a string to the equivalent boolean
function stringToBoolean(str) {
const string = (typeof str === 'string') ? str.toLowerCase().trim() : str
switch (string) {
case "true": case "yes": case "1": return true
case "false": case "no": case "0": case null: return false
default: return Boolean(string)
}
}
// Usage
@Uvacoder
Uvacoder / netlify-plugins.md
Created January 2, 2022 01:49 — forked from DavidWells/netlify-plugins.md
Netlify Plugin Spec

Simple plugin

Here is a simple plugin with no config and it runs on a single lifecycle event postBuild

// Plugin code
@Uvacoder
Uvacoder / get-npm-download-count.js
Created January 2, 2022 01:50 — forked from DavidWells/get-npm-download-count.js
Get npm download count by period
const path = require('path')
const fetch = require('node-fetch')
const flatcache = require('flat-cache')
/* Download API
period: Joi.string().regex(/(\d{4}-\d{2}-\d{2}(:\d{4}-\d{2}-\d{2})?|[\w-]+)/).required(),
Package "package-name", last week:
/downloads/point/last-week/package-name
Package "package-name", given 7-day period:
@Uvacoder
Uvacoder / tiny-markdown-text.md
Created January 2, 2022 01:50 — forked from DavidWells/tiny-markdown-text.md
Tiny tiny markdown text

How to make tiny text in markdown

Normal text here. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer vitae mauris arcu, eu pretium nisi. Vivamus vitae mi ligula, non hendrerit urna. Suspendisse potenti. Quisque eget massa a massa semper mollis.

Tiny text is here. Awwwww its so cuteeeeeeeeeee

Normal big text

function stringify(obj_from_json){
if(typeof obj_from_json !== "object" || Array.isArray(obj_from_json)){
// not an object, stringify using native function
return JSON.stringify(obj_from_json);
}
// Implements recursive object serialization according to JSON spec
// but without quotes around the keys.
let props = Object
.keys(obj_from_json)
.map(key => `${key}:${stringify(obj_from_json[key])}`)
service: my-service
custom:
one: 'hello'
two: 'there'
together: ${merge(${custom.one}, ${custom.two})}
# ^ resolves to 'hellothere'
provider:
name: aws
@Uvacoder
Uvacoder / compare-objects.js
Created January 2, 2022 18:41 — forked from DavidWells/compare-objects.js
Shallow compare objects and get diffs
const isEqual = require('lodash.isequal')
function compareNewToOld(newValues, oldValues) {
const initialData = {
// default everything is equal
isEqual: true,
// Keys that are different
keys: [],
// Values of the keys that are different
diffs: {}