Skip to content

Instantly share code, notes, and snippets.

View eiriklv's full-sized avatar
🤒
Out sick - I may be slow to respond.

Eirik L. Vullum eiriklv

🤒
Out sick - I may be slow to respond.
View GitHub Profile
// It is important to declare your variables.
(function() {
var foo = 'Hello, world!';
print(foo); //=> Hello, world!
})();
// Because if you don't, the become global variables.
(function() {
@eiriklv
eiriklv / getMetaProperty.js
Created September 28, 2014 11:11
Get meta property values with jquery
function getMetaProperty($, wantedProperty) {
var meta = $('meta');
var keys = Object.keys(meta);
var metaProperty;
keys.forEach(function (key) {
if (meta[key].attributes && meta[key].attributes.property && meta[key].attributes.property.value === wantedProperty) {
metaProperty = meta[key].content;
}
exports.ext = function () {
var extTypes = {
"3gp" : "video/3gpp"
, "a" : "application/octet-stream"
, "ai" : "application/postscript"
, "aif" : "audio/x-aiff"
, "aiff" : "audio/x-aiff"
, "asc" : "application/pgp-signature"
, "asf" : "video/x-ms-asf"
, "asm" : "text/x-asm"
@eiriklv
eiriklv / global.js
Last active August 29, 2015 14:07 — forked from soyuka/global.js
//global variable
test = 'hello';
//is exactly the same as
global.test = 'hello';
//local variable - this will definitly override your global variable
var test = 'world';
//using the process scope, if, and really if, you can't do without a global variable
@eiriklv
eiriklv / mongoose.js
Created October 3, 2014 08:24
Mongoose error handling and automatic reconnect
var debug = require('debug')('mongoose-setup')
module.exports.db = function (mongoose, config){
function connect() {
mongoose.connect(config.get('mongo_url'));
}
// connection is open and ready
mongoose.connection.on('open', function (ref) {
debug('open connection to mongo server.');
(function() {
var CSSCriticalPath = function(w, d, opts) {
var opt = opts || {};
var css = {};
var pushCSS = function(r) {
if(!!css[r.selectorText] === false) css[r.selectorText] = {};
var styles = r.style.cssText.split(/;(?![A-Za-z0-9])/);
for(var i = 0; i < styles.length; i++) {
if(!!styles[i] === false) continue;
var pair = styles[i].split(": ");
<!DOCTYPE html>
<html>
<head>
<meta charset=utf-8 />
<title>JS Bin</title>
</head>
<body>
<h2>Original CSS</h2>
<style style="display: block; white-space: pre; font-family: monospace">
h2 { margin:0; }
@eiriklv
eiriklv / component-using-mixin.js
Last active June 4, 2019 09:09
React Masonry Mixin Example
/** @jsx React.DOM */
'use strict';
var React = require('react');
var MasonryMixin = require('./react-masonry-mixin.js');
var masonryOptions = {
transitionDuration: 0
var StoreListenerMixin = function(...stores) {
var StoreMixin = {
getInitialState() {
return this.getStateFromStores(this.props);
},
componentDidMount() {
stores.forEach(store => store.addChangeListener(this.handleStoresChanged));
this.setState(this.getStateFromStores(this.props));
@eiriklv
eiriklv / gist:e96b4f74cb368e14bd7b
Last active August 29, 2015 14:07 — forked from jimbojsb/gist:1630790
Syntax highlighting in Keynote

Step 0:

Get Homebrew installed on your mac if you don't already have it

Step 1:

Install highlight. "brew install highlight". (This brings down Lua and Boost as well)

Step 2: