Skip to content

Instantly share code, notes, and snippets.

View cjohansen's full-sized avatar

Christian Johansen cjohansen

View GitHub Profile
@cjohansen
cjohansen / vdom.html
Created March 11, 2024 15:00
En liten virtuell DOM-implementasjon
<!DOCTYPE html>
<html>
<head>
<title>Virtuell DOM fra bunnen av</title>
<meta charset="utf-8">
</head>
<body>
<script src="vdom.js"></script>
</body>
</html>
@cjohansen
cjohansen / pliable-search.js
Created October 9, 2023 20:45
En bitteliten søkemotor i JavaScript
function groupBy(xs, f) {
var res = {};
(xs || []).forEach(x => {
var k = f ? f(x) : x;
if (!res[k]) {
res[k] = [];
}
res[k].push(x);
});
@cjohansen
cjohansen / gist:4135065
Created November 23, 2012 10:43
Naming this in nested functions

tl;dr

If you must nest functions in a way that requires access to multiple this', alias outer this to something meaningful - describe the value it's holding. Treat this as the invisible first argument.

In general though, avoiding the situation (nested functions and frivolous use of this) will frequently produce clearer results.

Naming this in nested functions

I was accidentally included in a discussion on how to best name this in nested functions in JavaScript. +1's were given to this suggestion of using _this.

Giving style advice on naming nested this without a meaningful context isn't too helpful in my opinion. Examples below have been altered to have at least some context, although a completely contrived and stupid one.

@cjohansen
cjohansen / reactorama.js
Created May 27, 2015 10:07
createComponent is 18 lines of JavaScript that puts a lean and enjoyable interface on top of React's somewhat clunky and non-JSX-hostile API.
// Most components are defined fully by their render function,
// and all they need to access is the props
var myComponent = createComponent(function (props) {
return React.DOM.h1({}, "Hello " + props.name);
});
// ...which can be done very succinctly with ES6:
const {h1, div} = React.DOM;
const myComponent = createComponent(({name}) => h1({}, `Hello ${name}`));
@cjohansen
cjohansen / float.html
Last active September 24, 2020 11:23
<!DOCTYPE html>
<html>
<head>
<style type="text/css">
.container {
width: 500px;
height: 500px;
border: 1px solid red;
overflow: hidden;
}
(defprotocol ExtMetaProtocol
:extend-via-metadata true
(ext-meta-protocol [x]))
(ext-meta-protocol (with-meta {} {`ext-meta-protocol (fn [_] 1)})) ;;=> 1
(extend-type clojure.lang.PersistentArrayMap
ExtMetaProtocol
(ext-meta-protocol [m]
2))
@cjohansen
cjohansen / gist:739589
Created December 13, 2010 20:55
Showing how to fake server requests with Sinon.JS and Jasmine
/*
Load Sinon.JS in the SpecRunner:
<script type="text/javascript" src="lib/jasmine-1.0.1/jasmine.js"></script>
<script type="text/javascript" src="lib/jasmine-1.0.1/jasmine-html.js"></script>
<script type="text/javascript" src="sinon-1.0.0.js"></script>
<script type="text/javascript" src="sinon-ie-1.0.0.js"></script>
http://cjohansen.no/sinon/
*/
@cjohansen
cjohansen / buster-server.sh
Created May 10, 2012 19:45
Run the Buster.JS server with a Phantom.JS client
#!/bin/bash
# Based on work by Tiago Rodrigues
# Here: http://trodrigues.net/presentations/buster-ci/#/24
# And here: https://gist.github.com/2630210
# Usage:
# env BUSTER_HOME=/where/you/installed/buster ./buster-server.sh start|stop
function buster_server_pid(){
echo `ps aux|grep buster-server|grep node|awk '{ print $2 }'`

Beskrivelse av oppdraget

NRK utvikler nye løsninger for forvaltning av arkivinnhold for radio og TV. Et av målene er å tilrettelegge innhold og metadata for enklere og raskere publisering gjennom flere kanaler (lineær, nett, mobil) enn før. I tillegg skal løsningene levere infrastruktur for selvbetjening av publikum og «content-on-demand» gjennom bla. programspilleren (tv.nrk.no / radio.nrk.no).

Det er besluttet at tjenestene i størst mulig grad skal utvikles eller tilpasses i nært samarbeid med NRKs eksisterende utviklingsmiljø og at kunnskapsoverføring og kompetanseheving er viktige mål. Pedagogiske evner, evne til å kommunisere og

@cjohansen
cjohansen / react.js
Last active September 15, 2016 09:26
function appUI(actions) {
return React.createClass({
render: function () {
return React.DOM.h1({onClick: actions.doit}, 'LOL');
}
});
}
var data = {}