Skip to content

Instantly share code, notes, and snippets.

View evanwinter's full-sized avatar

Evan Winter evanwinter

View GitHub Profile
@evanwinter
evanwinter / scrape-public-website-html.js
Last active July 29, 2020 20:13
Bare minimum script for scraping a website with Node.js
const fetch = require("node-fetch")
const { JSDOM } = require("jsdom")
const fetchHtml = async (url) => {
const response = await fetch(url)
const text = await response.text()
const dom = new JSDOM(text)
return dom.window.document
}
@evanwinter
evanwinter / send-sms-text-message-with-node-js-twilio.js
Created July 29, 2020 19:56
Send an SMS text message using the Twilio API and Node.js SDK.
const twilio = require("twilio")
const accountSid = "<MY_TWILIO_ACCOUNT_SID>"
const authToken = "<MY_TWILIO_AUTH_TOKEN>"
const client = new twilio(accountSid, authToken)
client.messages.create({
body: "Hello from Node.js",
to: "<TARGET_PHONE_NUMBER>",
from: "<MY_TWILIO_PHONE_NUMBER>"
}).then((message) => console.log(message.sid))
const array = ['a', 'b', 'c']
const current = 0
const last = array.length - 1
const prev = (current === 0) ? last : current-1
const next = (current === last) ? 0 : current+1
@evanwinter
evanwinter / jobr.js
Last active October 8, 2019 17:19
Automate Jobr time entry
/*
Usage
-----
1. Copy and paste the jobr() function below into a new text file, and update the "tasks" array to use your own tasks.
2. Go to Jobr in Chrome (or probably any other browser).
2. Select the day you're entering time for.
@evanwinter
evanwinter / simpleReduce.js
Created June 4, 2019 14:36
Simple examples of Array::reduce
const numbers = [1, 3, 5, 1, 23, 5]
// Adds two args
const add = (one, two) => one + two
// Compute sum of the collection
const sum = numbers.reduce((sum, number) => add(sum, number))
// Multiplies two args
const multiply = (one, two) => one * two
@evanwinter
evanwinter / getObjFromArrayByID.js
Created June 3, 2019 20:57
Take an array of objects, and return an object containing those objects, indexable by a property.
const input = [
{
"id": "b297ed8f-ad81-5988-a08e-b4ec51428981",
"questionBody": "What generations are you primarily serving?",
"questionAnswers": [
"Gen Z (1997-on)",
"Millennials (1981-1997)",
"Gen X (1965-1980)",
"Boomers (1946-1964)"
],
@evanwinter
evanwinter / scss-to-camel.js
Last active February 21, 2019 19:44
scss variables to camel case keys
const vars = [
// nav
"$nav-bg-color",
"$nav-text-color",
"$nav-default-height",
"$nav-font-family",
"$nav-border-bottom",
"$nav-box-shadow",
"$nav-link-color",
"$nav-link-color-hover",
@evanwinter
evanwinter / loadEmployee.js
Last active November 29, 2018 16:03
Sample code for handling API calls via Redux.
// via https://medium.com/react-weekly/implementing-graphql-in-your-redux-app-dad7acf39e1b
import {
LOAD_EMPLOYEE_DATA_INITIATION,
LOAD_EMPLOYEE_DATA_SUCCESS,
LOAD_EMPLOYEE_DATA_FAILURE,
} from './constants';
export const employeeUrl = 'http://0.0.0.0:1338/api/employees';
// loadEmployeeDataInitiation :: None -> {Action}
export const loadEmployeeDataInitiation = () => ({
@evanwinter
evanwinter / addReporterAsParticipant.groovy
Last active April 2, 2019 17:02
Adds initial Reporter as a Participant, and sets the user in custom field "Primary User" as the new Reporter. For use in JIRA Service Desk.
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.event.type.EventDispatchOption
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.issue.IssueManager
import java.util.ArrayList
import com.atlassian.jira.user.ApplicationUser
import org.apache.log4j.Logger
def log = Logger.getLogger("com.acme.XXX")
package examples.docs
import com.atlassian.applinks.api.ApplicationLink
import com.atlassian.applinks.api.ApplicationLinkService
import com.atlassian.applinks.api.application.confluence.ConfluenceApplicationType
import com.atlassian.sal.api.component.ComponentLocator
import com.atlassian.sal.api.net.Request
import com.atlassian.sal.api.net.Response
import com.atlassian.sal.api.net.ResponseException
import com.atlassian.sal.api.net.ResponseHandler