Skip to content

Instantly share code, notes, and snippets.

Avatar

Christian Johansen cjohansen

View GitHub Profile
@cjohansen
cjohansen / gist:4135065
Created November 23, 2012 10:43
Naming this in nested functions
View gist:4135065

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.
View reactorama.js
// 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
View float.html
<!DOCTYPE html>
<html>
<head>
<style type="text/css">
.container {
width: 500px;
height: 500px;
border: 1px solid red;
overflow: hidden;
}
View protocols.cljs
(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
View gist:739589
/*
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
View buster-server.sh
#!/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 }'`
View utlysning.md

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
View react.js
function appUI(actions) {
return React.createClass({
render: function () {
return React.DOM.h1({onClick: actions.doit}, 'LOL');
}
});
}
var data = {}
@cjohansen
cjohansen / gist:739597
Created December 13, 2010 21:00
Mocking jQuery.ajax with Sinon.JS
View gist:739597
describe("SinonMockJQAjaxWithJasmine", function() {
it("should mock a jQuery ajax request", sinon.test(function () {
this.mock(jQuery).expects("ajax").once();
jQuery.ajax({
url: "/something"
});
}));
it("should fail when expectations are not met", sinon.test(function () {
View drawer.js
import {createComponent} from 'origo-react';
import {DOM, createFactory} from 'react';
import {findDOMNode} from 'react-dom';
const {div} = DOM;
export const Drawer = createComponent({
componentWillAppear(callback) {
this.componentWillEnter(callback);
},