Skip to content

Instantly share code, notes, and snippets.

View rs77's full-sized avatar

Ryan rs77

View GitHub Profile
@rs77
rs77 / sort-table-metro-ui.html
Created July 26, 2024 22:44
Full minimal example of creating a sortable table in Metro UI
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Sortable Table with Metro-UI</title>
<link rel="stylesheet" href="https://cdn.metroui.org.ua/v4/css/metro-all.min.css">
</head>
<body>
<table class="table" data-role="table">
@rs77
rs77 / copy_table_row_with_selects_metroui.html
Created July 23, 2024 11:45
Copying table row with select statements and recasting the newly copied select statements using MetroUI
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="https://cdn.metroui.org.ua/current/metro.css">
</head>
<body>
<table class="table">
<thead>
<tr>
<th>Header</th>
@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