Skip to content

Instantly share code, notes, and snippets.

View rs77's full-sized avatar

Ryan rs77

View GitHub Profile
@rs77
rs77 / csv-to-list-of-dictionaries-python-template.py
Created January 26, 2024 00:25
Here's a template I use to convert a CSV file to a list of dictionaries in Python, read more about it here: https://scripteverything.com/read-a-csv-file-to-list-of-dictionaries-in-python/
# The list for where the dictionaries will be stored
result = list()
with open(file_path) as f:
# Do I need to cleanse the keys?
# Yes: but I will manually write the headers...
my_headers = ('Header 1', 'Header 2')
# Yes: but I just want to clean the current headers...
@rs77
rs77 / summarize-map-reduce-fn.js
Created November 13, 2023 21:35
Suitescript summarize function for a Map/Reduce script
const summarize = (summaryContext) => {
log.debug({title: 'SUMMARY', details: summaryContext});
if (summaryContext.inputSummary.error) {
log.error({title: 'INPUT ERROR', details: summaryContext.inputSummary.error});
}
summaryContext.mapSummary.errors.iterator().each(
(key, error) => {
log.error({title: `MAP ERROR: ${key}`, details: error});
return true;
}
@rs77
rs77 / payment_amount.js
Last active April 6, 2024 04:23
Payment amount function for the equivalent PMT() formula seen in Google Sheets and Excel.
/**
* Payment amount formula as seen in Google Sheets/Excel PMT()
* @param {Number} rate - as a decimal not as a percentage, per period
* @param {Number} nper - total number of periods remaining, needs to be the same period as rate
* @param {Number} pval - present value
* @param {Number} [fv=0] - future value (default is 0)
* @param {Number} [type=0] - is payment in arrears, paid at the end of each period, (0) or in advance, paid at the start of each period (1) (default is 0 = arrears)
* @returns {Number}
*/
function pmt(rate, nper, pval, fv = 0, type = 0) {
@rs77
rs77 / future_value.js
Last active April 6, 2024 04:22
Future Value formulas as seen in Excel in Google Sheets written in Javascript format.
/**
* Future Value formula as detailed in Google Sheets/Excel
* @param {Number} rate - as a decimal not as a percentage per period
* @param {Number} nper - total number of periods remaining, needs to be the same period as rate
* @param {Number} [pymt=0] - amount paid per period (optional is pval is not 0, otherwise default is 0)
* @param {Number} [pval=0] - present value of the annuity (optional if pymt is 0, otherwise default is 0)
* @param {Number} [type=0] - is payment in arrears, paid at the end of each period, (0) or in advance, paid at the start of each period (1) (default is 0 = arrears)
* @returns {Number}
*/
function fv(rate, nper, pymt = 0, pval = 0, type = 0) {
@rs77
rs77 / present_value.js
Last active April 6, 2024 04:24
Present Value formula matching Excel and Google Sheets written in Javascript
/**
* Present Value formula as detailed in Google Sheets/Excel
* @param {Number} rate - as a decimal not as a percentage per period
* @param {Number} nper - total number of periods remaining, needs to be the same period as rate
* @param {Number} pmt - amount paid per period
* @param {Number} [fv=0] - future value of the annuity (default 0)
* @param {Number} [type=0] - is payment in arrears, paid at the end of each period, (0) or in advance, paid at the start of each period (1) (default is 0 = arrears)
* @returns {Number}
*/
function pv(rate, nper, pmt, fv = 0, type = 0) {
@rs77
rs77 / convert_json_to_csv.py
Created June 2, 2023 22:21
Simple example converting JSON data and exporting to CSV file.
import json
import csv
json_raw = """
{
"employees": [{
"name": "John Smith",
"salary": 120000
},{
"name": "Jane Doe",
import requests
from bs4 import BeautifulSoup
response = requests.get("https://example.com")
soup = BeautifulSoup(response.text, 'html.parser')
# define what common attributes the html tags contain
anchors = soup.find_all("a")
links = [a for a in anchors if a['href'].lower().endswith(".pdf")]
@rs77
rs77 / my_cs_custom_code.js
Last active March 11, 2023 02:56
This is the client script that needs to be uploaded to the File Cabinet. It does not need to be registered with a Script Record, but must satisfy the location of the User Event Script `clientScriptModule` (or the User Event Script's `clientScriptFileId`). More details here: http://scripteverything.com/update-record-with-button-when-viewing-in-br…
/**
* @NApiVersion 2.x
* @NScriptType ClientScript
* @NModuleScope SameAccount
*/
define(['N/record', 'N/currentRecord', 'N/url'],
/**
* @param {record} record
* @param {currentRecord} currentRecord
* @param {url} url
@rs77
rs77 / my_ue_add_client_side_button.js
Last active March 11, 2023 02:56
How do you add a button on a record to perform an update to that record? Start with the User Event Script that needs to be uploaded to the File Cabinet and requires a Script Record. Then deploy the Script to the records that this needs to be attached to. More info here: http://scripteverything.local/update-record-with-button-when-viewing-in-brow…
/**
* @NApiVersion 2.1
* @NScriptType UserEventScript
* Insert a client side button to update a record.
*/
define([],
() => {
const beforeLoad = (context) => {
try {
/** @type {Record} */
@rs77
rs77 / rename_folder_mac_os_using_python
Last active January 8, 2023 05:19
I had to rename the folders in a sub-directory on my Mac OS to lower case and this was the only code I could get to work. It appears you need to remove the directory and create a new one with the right case, you cannot simply use `os.rename`
import glob
import pathlib
import shutil
import os
src = '/Users/rds/Local Sites/biblejot/app/public_static/kjv/**/index.html'
temp = '/Users/rds/Local Sites/biblejot/app/public_static/kjv/temp/'
path = pathlib.Path(temp)
path.mkdir(parents=True, exist_ok=True)