Skip to content

Instantly share code, notes, and snippets.


Marc Khoury koganei

View GitHub Profile
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) {
View unlockanimation.js
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 /
Last active August 29, 2015 14:19

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

koganei / fizzbuzz.clj
Last active August 29, 2015 14:10
Haskell & Clojure Fizzbuzz
View fizzbuzz.clj
(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 / app.js
Created August 5, 2014 17:04
AngularJS DB Interface Layer
View app.js
* 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 / poemsApiService.js
Last active August 29, 2015 14:04
An attempt to find the best way to structure a Restangularized API service
View poemsApiService.js
(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 /
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