Skip to content

Instantly share code, notes, and snippets.

View fentas's full-sized avatar
🐷
Oink.

Jan Guth fentas

🐷
Oink.
View GitHub Profile
@fentas
fentas / app.js
Last active August 29, 2015 13:58 — forked from ryanflorence/static_server.js
Simple nodejs server. Just serving files with mime types (-file ext).
#!/usr/bin/node
var http = require("http"),
url = require("url"),
path = require("path"),
fs = require("fs")
port = process.argv[2] || 3000,
root = process.argv[3] || '/www',
mime = {".3dm":"x-world/x-3dmf",".3dmf":"x-world/x-3dmf",".a":"application/octet-stream",".aab":"application/x-authorware-bin",".aam":"application/x-authorware-map",".aas":"application/x-authorware-seg",".abc":"text/vnd.abc",".acgi":"text/html",".afl":"video/animaflex",".ai":"application/postscript",".aif":"audio/x-aiff",".aifc":"audio/x-aiff",".aiff":"audio/x-aiff",".aim":"application/x-aim",".aip":"text/x-audiosoft-intra",".ani":"application/x-navi-animation",".aos":"application/x-nokia-9000-communicator-add-on-software",".aps":"application/mime",".arc":"application/octet-stream",".arj":"application/octet-stream",".art":"image/x-jg",".asf":"video/x-ms-asf",".asm":"text/x-asm",".asp":"text/asp",".asx":"video/x-ms-asf-plugin",".au":"audio/x-au",".avi":"video/x-msvideo",".avs":"video/avs-video",".bcpio":"ap
@fentas
fentas / cookies.js
Created April 9, 2014 16:36
Simple js for converting cookie string into object
cookies = {};
// read out cookies
document.cookie.replace(/([^=;]+)=([^;]*)/gi, function(m,key,value) {cookies[key.replace(/(^\s+|\s+$)/g,'')] = value.replace(/(^\s+|\s+$)/g,'');});
@fentas
fentas / prevent-ghost-event.js
Last active August 29, 2015 14:00
prevent ghost click issue - tap event triggered for twice (jquery mobile)
if ( typeof lastTabEvent !== 'undefined' && +new Date() - 500 < lastTabEvent) return; else lastTabEvent = +new Date();
/*
$('...').bind('tap', function(e) {
if ( typeof lastTabEvent !== 'undefined' && +new Date() - 500 < lastTabEvent) return; else lastTabEvent = +new Date();
// ...
});
@fentas
fentas / gist:11213785
Created April 23, 2014 12:43
simple jquery autocompletion / list filter
/*
<input >
<ul>
<li text="test">test</li>
<li text="foo">foo value</li>
</ul>
*/
$('input').keyup(function(e) {
var ul = $(this).next();
(function (window, document, $, undefined) {
var possibleCharacters = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
var defaults = {
selector: "#captcha",
text: null,
randomText: true,
randomColours: true,
@fentas
fentas / gist:cc3846891b5f49ed353c
Last active August 29, 2015 14:04
ATOM - grammar scrope names

ATOM's grammar scope names

  • source.gfm GitHub Markdown
  • source.yaml YAML
  • source.coffee CoffeeScript
  • source.litcoffee CoffeeScript (Literate)
  • source.js JavaScript
  • source.js.regexp Regular Expressions (JavaScript)
  • text.xml.xsl XSL
  • text.xml XML
  • source.go Go
@fentas
fentas / zoomOnClick.js
Created June 25, 2015 19:02
Adds zoomOnClick functionality to datamap (d3)
(function(Datamap, d3) {
var centered
function clickZoom(d) {
var self = this,
zoomFactor = self.options.zoomConfig.zoomFactor,
width = self.options.element.clientWidth,
height = self.options.element.clientHeight,
bounds;
if (centered === d
@fentas
fentas / gist:fa79167a82bf15160421
Created June 26, 2015 17:42
Multi-line strings in JavaScript and Node.js
var html = (function () {/*
2 <!DOCTYPE html>
3 <html>
4 <body>
5 <h1>Hello, world!</h1>
6 </body>
7 </html>
8 */}).toString().match(/[^]*\/\*([^]*)\*\/\}$/)[1];
@fentas
fentas / openflights-airports.js
Created July 4, 2015 11:03
Download and output airport database as geojson (openflights.org)
#!/usr/bin/env node
var got = require('got'),
csv = require('csv-parser'),
through = require('through2'),
geojsonStream = require('geojson-stream');
/**
* Download and output airport database
*
.my-container { position: relative; background: #5C97FF; overflow: hidden; } /* You could use :after - it doesn't really matter */ .my-container:before { content: ' '; display: block; position: absolute; left: 0; top: 0; width: 100%; height: 100%; z-index: 1; opacity: 0.6; background-image: url('http://placekitten.com/1500/1000'); background-repeat: no-repeat; background-position: 50% 0; -ms-background-size: cover; -o-background-size: cover; -moz-background-size: cover; -webkit-background-size: cover; background-size: cover; }