Skip to content

Instantly share code, notes, and snippets.

View u007's full-sized avatar
🏠
Working from home

James u007

🏠
Working from home
View GitHub Profile
@u007
u007 / docker-compose.yml
Created January 25, 2019 12:23
docker-compose for logrotate
version: "3.2"
services:
logrotate:
image: blacklabelops/logrotate
restart: unless-stopped
volumes:
- "/home/yourpathtolog:/log"
- "./logrotate-status:/logrotate-status"
environment:
- "LOGS_DIRECTORIES=/log"
@u007
u007 / .eslintrc.js
Created March 13, 2019 09:36
nuxt + typescript + prettier
module.exports = {
root: true,
env: {
browser: true,
node: true
},
parser: 'vue-eslint-parser',
parserOptions: {
'parser': '@typescript-eslint/parser',
'ecmaVersion': 2017,
@u007
u007 / source.js
Last active March 19, 2019 15:07
mongodb stitch function for database trigger to save updated_at and created_at
exports = function(changeEvent) {
console.log("changed", changeEvent.operationType, JSON.stringify(Object.keys(changeEvent)))
//allows replace and create
if(changeEvent.operationType == "update") {
let keys = Object.keys(changeEvent.updateDescription.updatedFields)
console.log("changed", JSON.stringify(Object.keys(changeEvent.updateDescription.updatedFields)))
if(keys.indexOf('created_at') > -1 || keys.indexOf('updated_at') > -1 || keys.length == 0) {
//changed fields contains created_at or updated_at
// on $set, it will trigger "update"
console.log("ignoring change")
@u007
u007 / somefunction.js
Created June 26, 2019 09:08
firebase function get current logged in user
const auth: any = context.auth || {}
if (!auth || !auth.uid) {
//not logged in
}
let authUser = await admin.auth().getUser(auth.uid)
@u007
u007 / README.md
Last active May 26, 2020 17:18
resizing /tmp cpanel centos 7 on linode

goto linode dashboard > node

1st, setting > shutdown watchdog > disable

second, boot into rescue mode

disclaimer: i'm not responsible for any problems with your system (but you may contact me)

mkdir /mnt/r
@u007
u007 / api_category_config_schema.graphql
Last active February 6, 2021 13:53
strapi graphql with nested field
const { find2 } = require('../controllers/category')
module.exports = {
definition: `
type Category2 {
id: ID!
created_at: DateTime!
updated_at: DateTime!
Title: String
Icon: String
@u007
u007 / multerconfig.js
Last active October 12, 2021 07:05
multer s3 contentType fix
import stream from 'stream';
const mime = require('mime-types');
import aws from 'aws-sdk';
import multer from 'multer';
import multerS3 from 'multer-s3';
multer({
//...,
storage: multerS3({
@u007
u007 / Makefile
Created October 1, 2022 11:22
upgrade package.json to all compatible version
upgrade:
npx ts-node-esm ./upgrade.ts
npm update -S
@u007
u007 / setup.php
Created July 13, 2023 03:17
php code to generate .env from elasticbeanstalk environment variables
<?php
// setup .env from $_ENV
file_put_contents('/var/www/html/.env', '');
foreach ($_ENV as $key => $value)
{
if (
strpos($key, 'PHP_') === 0 ||
strpos($key, 'NOTIFY_') === 0 ||
strpos($key, 'HTTP_') === 0 ||
@u007
u007 / count.ts
Created July 24, 2023 02:41
openai get token count via TS
import * as tiktoken from 'tiktoken'
import { TiktokenModel } from 'tiktoken'
// @thanks https://stackoverflow.com/questions/76216113/how-can-i-count-tokens-before-making-api-call
export const calculateTokenCount = async (text: string, model : TiktokenModel = 'gpt-3.5-turbo') => {
try {
const tk = await tiktoken.encoding_for_model(model)
const encoded = tk.encode(text)
return encoded.length
} catch (error: any) {