Skip to content

Instantly share code, notes, and snippets.

interface SemaHandle {
release(): void;
}
function createSema(concurrency: number): { acquire(): Promise<SemaHandle> } {
let handles: string[] = [];
const queue: ((value: unknown) => void)[] = [];
function createHandle(): string {
const handle = nanoid();
@adriancooney
adriancooney / route.ts
Created April 29, 2023 16:38
Create a ReadableStream from a OpenAI GPT3/4 LangChain chain for Edge streaming
import { OpenAI } from "langchain/llms/openai";
import { PromptTemplate } from "langchain/prompts";
import { LLMChain } from "langchain/chains";
import { streamCall } from "./stream-call"
export const config = {
runtime: "edge",
};
export async function GET(request: Request) {
import { RESTAdapter } from 'ember-data/adapter';
console.log("here")
export default RESTAdapter.extend({});
import Ember from 'ember';
import { inject as service } from '@ember/service';
export default Ember.Controller.extend({
store: service(),
appName: 'Ember Twiddle',
async init() {
// Open the console
this.loadDog(1);
@adriancooney
adriancooney / adapters.draft.js
Last active August 27, 2019 11:12
Ember save / set
import DS from 'ember-data';
export default DS.JSONAPIAdapter.extend({
updateRecord(store, type, { record }) {
console.log("Saving draft", record.id);
return sleep(1000);
},
createRecord(store, type, { record }) {
console.log("Creating draft", record.body);
@adriancooney
adriancooney / controllers.application.js
Created August 13, 2019 13:03
Ember Data Set & Load
import Ember from 'ember';
import { inject as service } from '@ember/service';
export default Ember.Controller.extend({
store: service(),
appName: 'Ember Twiddle',
logs: Ember.A([]),
init() {
// Add an example record
import Ember from 'ember';
export default Ember.Controller.extend({
appName: 'Ember Twiddle',
a: Ember.computed(function() {
return 1;
}),
init() {
import Ember from 'ember';
import { inject as service } from '@ember/service';
export default Ember.Controller.extend({
appName: 'Ember Twiddle',
store: service(),
init() {
this.store.push({
data: [{
@adriancooney
adriancooney / controllers.application.js
Created July 9, 2019 11:22
Ember Data Relationships
import Ember from 'ember';
export default Ember.Controller.extend({
appName: 'Ember Twiddle',
});
@adriancooney
adriancooney / controllers.application.js
Last active April 8, 2019 13:21
Ember 3.4 Scheduler Issue
import Ember from 'ember';
import { later, debounce } from '@ember/runloop';
export default Ember.Controller.extend({
sync(schedulerType) {
console.log("syncing via", schedulerType);
},
actions: {
case1() {