My Elasticsearch cheatsheet with example usage via rest api (still a work-in-progress)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Octokit } from "@octokit/rest"; | |
import OpenAI from "openai"; | |
import "dotenv/config"; | |
const octokit = new Octokit({ auth: process.env.GH_TOKEN }); | |
const openai = new OpenAI({ | |
apiKey: process.env.OPENAI_API_KEY, | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { ChatCompletionRequestMessage, Configuration, OpenAIApi } from "openai"; | |
var prompt = require("prompt-sync")(); | |
require("dotenv").config(); | |
const configuration = new Configuration({ | |
apiKey: process.env.OPENAI_API_KEY, | |
}); | |
const openai = new OpenAIApi(configuration); | |
async function getWeather(location: string, unit = "fahrenheit") { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
apiVersion: v1 | |
kind: ConfigMap | |
metadata: | |
name: nginx-conf | |
data: | |
nginx.conf: | | |
user nginx; | |
worker_processes 3; | |
error_log /var/log/nginx/error.log; | |
events { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import clr | |
import sys | |
import os.path | |
clr.AddReference("Microsoft.Office.Interop.Excel") | |
from Microsoft.Office.Interop import Excel | |
from System import Type, GC | |
# See http://msdn.microsoft.com/en-us/library/bb407651.aspx for |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function Semaphore(max) { | |
var counter = 0; | |
var waiting = []; | |
var take = function() { | |
if (waiting.length > 0 && counter < max){ | |
counter++; | |
let promise = waiting.shift(); | |
promise.resolve(); | |
} |
Javascript is a programming language with a peculiar twist. Its event driven model means that nothing blocks and everything runs concurrently. This is not to be confused with the same type of concurrency as running in parallel on multiple cores. Javascript is single threaded so each program runs on a single core yet every line of code executes without waiting for anything to return. This sounds weird but it's true. If you want to have any type of sequential ordering you can use events, callbacks, or as of late promises.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# The OAuth access token provided by the Google API expires in 60 minutes. After expiration, | |
# you must exchange a refresh token for a new access token. Unfortunately, the the Google API | |
# ruby gem does not include a method for refreshing access tokens. | |
# You can read up on how to refresh an access token here: | |
# https://developers.google.com/accounts/docs/OAuth2WebServer#refresh | |
# This Token model implements that process. It's based off of a Token model that can be created | |
# by running: | |
# rails g model Token token:text refresh_token:string expires_at:datetime |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package workerpool | |
import ( | |
"context" | |
) | |
/* | |
* Worker Pool for executing heavy tasks to avoid OOM error from OS | |
* Usage example: | |
* pool := workerpool.NewPool(3) // Number of workers should be adjusted appropriately to your services |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var AWS_KEY = '<your key>'; | |
var AWS_SECRET = '<your secret>'; | |
function generateS3Url(bucket, path) { | |
var expiresDt = Math.floor(Date.now() / 1000) + (60 * 60 * 24); // can be up to 7 days from now | |
var stringToSign = 'GET\n\n\n' + expiresDt + '\n/' + bucket + '/' + encodeURIComponent(path); | |
var hmac = Utilities.computeHmacSignature(Utilities.MacAlgorithm.HMAC_SHA_1, stringToSign, AWS_SECRET, Utilities.Charset.UTF_8); | |
var signed = encodeURIComponent(Utilities.base64Encode(hmac)); |
NewerOlder