Skip to content

Instantly share code, notes, and snippets.

ChatGPT Telnet

  • Download the files into a directory.
  • Replace the API key with your own in gpt.js
  • Run npm i
  • Run node .
  • Connect to it using telnet
@lordlycastle
lordlycastle / appScriptNuggets.js
Created April 14, 2021 17:40
Utility functions for AppScript from Google for Sheets. Taken from: https://community.appsheet.com/t/introducing-script-nuggets/41515
*
NAME: SCRIPT NUGGETS
DESCRIPTION: Apps Script functions for use with AppSheet
SETUP: Replace YOUR_SHEET_ID in first line with the sheet Id from the sheet URL
BY: GreenFlux, LLC
*//////////////////////////////////////////////////////////////////////////////////////////////////////
const ss = SpreadsheetApp.openById('YOUR_SHEET_ID');//(id from sheetURL)
@masautt
masautt / 5qpt0yu.js
Created November 7, 2019 22:37
FullStackFaqs - Code Answers
function roundUp(num, prec) {
prec = Math.pow(10, prec);
return Math.ceil(num * prec) / prec;
}
function roundDown(num, prec) {
prec = Math.pow(10, prec);
return Math.floor(num * prec) / prec;
}
// Built in Math function
@jlevy
jlevy / simple-hash.js
Last active April 20, 2024 17:54
Fast and simple insecure string hash for JavaScript
// These hashes are for algorithmic use cases, such as bucketing in hashtables, where security isn't
// needed and 32 or 64 bits is enough (that is, rare collisions are acceptable). These are way simpler
// than sha1 (and all its deps) or similar, and with a short, clean (base 36 alphanumeric) result.
// A simple, *insecure* 32-bit hash that's short, fast, and has no dependencies.
// Output is always 7 characters.
// Loosely based on the Java version; see
// https://stackoverflow.com/questions/6122571/simple-non-secure-hash-function-for-javascript
const simpleHash = str => {
let hash = 0;

(INCOMPLETE) Installing Wordpress + PHP-fpm from scratch on ubuntu

Install PHP

sudo apt-get install php-fpm # installs php7.2-fpm
sysctl status php7.2-fpm # checks status

Install NGINX to serve the PHP-fpm endpoint

@dsetzer
dsetzer / bet-utils.js
Last active November 16, 2023 03:04
A few martingale oriented inverse utility functions.
/**
* Calculates the base bet from the current wager, multiplier, and streak.
*
* @param {number} wager - The current wager.
* @param {number} multi - The multiplier.
* @param {number} streak - The streak.
* @returns {number} - The calculated base bet.
*/
const getBaseBetFromCurrent = (wager, multi, streak) => (wager / (multi ** streak));
@Prateek479
Prateek479 / async.js
Created March 20, 2016 16:43
Async parallel forEach and async forEach
function asyncParForEach(array, fn, callback) {
var completed = 0;
if (array.length === 0) {
callback(); // done immediately
}
array.forEach(function(data) {
fn(data, function() {
completed++;
if (completed === array.length) {
@webshooter
webshooter / class_def.js
Last active October 9, 2018 03:58
Javascript class definition template
var Thing = (function() {
this.public_property = "Public property";
var private_property = "Private property";
function Thing(data) {
this.datum1 = data.datum1;
this.datum3 = data.datum2;
}
@roadmanfong
roadmanfong / promiseWhile.js
Last active November 22, 2018 15:14
promiseWhile demo
function promiseWhile(condition, body) {
var dfd = $.Deferred();
function loop() {
if (!condition()) return dfd.resolve();
body.apply(this, arguments)
.done(loop)
.fail(dfd.reject);
}
//call loop async
@ScottKaye
ScottKaye / HandyDandyPrototypes.js
Last active July 10, 2023 19:16
A collection of potentially useful prototypes to make some things easier. Each of these should be crushable with http://www.iteral.com/jscrush/ . "Don't modify objects you don't own" is completely thrown out the window here in favour of coolness.
//Get a range of numbers between two numbers
//Usage: [1, 10].range returns [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
Object.defineProperty(Array.prototype, "range", {
get: function () {
var range = [this[0]], i;
for (var i = this[0], len = this[1]; i < len; range.push(++i));
return range;
}
});
// Golfed TypeScript: