Skip to content

Instantly share code, notes, and snippets.

View koganei's full-sized avatar

Marc Khoury koganei

View GitHub Profile
koganei /
Last active August 29, 2015 14:04
Event delegation in AngularJS
koganei /
Last active August 29, 2015 14:04
RESTful APIs + Git architecture

I've been reading some articles on RESTful APIs and it got me thinking that maybe it could profit from a git architecture.

The idea would be that when you PUT to api/dragons/haku, you are (git) staging a change to the /haku resource. A summary of the currently staged data is returned by the PUT, as well as HEAD revision number to see if the live data needs to be updated. Different sections of the APIs could have their own 'HEAD' number, so that we can know when the latest dragon has been edited, but not the latest imp.

Similarly, when you POST to /dragons, you are (git) adding a dragon to the resource repository. With GET, an HTTP header could say whether you would like the staged data, the live data or the data of a particular revision.

Semantically, it could be better to add a new verb COMMIT to commit to a certain resource, but it can easily be circumvented with _post variables or headers to support interoperability. A commit message is posted along with the COMMIT verb.

On the database side, I'm

koganei / poemsApiService.js
Last active August 29, 2015 14:04
An attempt to find the best way to structure a Restangularized API service
(function() {
'use strict';
* the poemsApi Service. Restangular has all the functions you would expect from an
* API service, so we return the Restangular resource object.
* @service poemsApi
* @param Restangular bower install restangular
* @return service object
koganei / app.js
Created August 5, 2014 17:04
AngularJS DB Interface Layer
* The idea is to expose an interface from the app side that a service can fulfill
angular.module('myapp', ['apiservice'])
* We load the service that fulfills the interface through a config on the app side
.factory('config', function(
koganei / fizzbuzz.clj
Last active August 29, 2015 14:10
Haskell & Clojure Fizzbuzz
(defn fizz-buzz []
(loop [i 1]
(if (<= i 100)
(if (and (= (rem i 3) 0) (= (rem i 5) 0))
(println "fizzbuzz")
(if (= (rem i 3) 0)
(println "fizz")
(if (= (rem i 5) 0)
(println "buzz")
koganei /
Last active August 29, 2015 14:19

[test]('javascript:return false;')

import $ from 'jquery';
import { angular } from './../../js/base';
import _ from 'lodash';
class unlockAnimation {
constructor($element, $rootScope) {
this.$rootScope = $rootScope;
this.listeners = {
click: this.onClick.bind(this),
koganei /
Created March 17, 2023 16:34
ChatGPT generation of an import map tool


Hi, can you give me the javascript code that will generate an import map for a given package.json so that code works in web browsers without any kind of building?


Certainly! Below is a JavaScript code snippet that generates an import map for a given package.json file. This code assumes that the dependencies in the package.json are already downloaded and placed in a folder named node_modules within your project directory, and it generates an import map compatible with native ES modules in web browsers without requiring a build step.

const fs = require("fs");

function generateImportMap(packageJsonPath) {
from typing import Optional
# from haystack.nodes.question_generator.question_generator import QuestionGenerator
from haystack.nodes.retriever.base import BaseRetriever
from haystack.nodes import PromptNode, Shaper, TopPSampler
from haystack.pipelines.base import Pipeline
from haystack.pipelines.standard_pipelines import BaseStandardPipeline
class ExtractiveQAWithPromptNodePipeline(BaseStandardPipeline):
koganei /
Created April 14, 2023 14:56
Using a langchain tool in a Haystack agent
def create_wolfram_alpha_tool():
from haystack.agents import Tool
from walpha_tool.tool import WolframAlphaNode
node = WolframAlphaNode()
return Tool(name="WolframAlpha",
description="A wrapper around Wolfram Alpha. " # Taken verbatim from the langchain code, could be done automatically somehow
"Useful for when you need to answer questions about Math,"
"Science, Technology, Culture, Society and Everyday Life."