Skip to content

Instantly share code, notes, and snippets.

View thekarel's full-sized avatar

Charles Szilagyi thekarel

View GitHub Profile
@thekarel
thekarel / server.js
Created July 20, 2013 11:19
Node.js server basic
// Run with node server.js
var cfg = {
http: {
port: 3333,
host: '127.0.0.1'
}
}
var http = require('http');
http.createServer(function(req, res) {
@thekarel
thekarel / is-a-number.js
Created July 21, 2013 12:08
Check if a variable is a number
// http://stackoverflow.com/a/1830844/129698
if ( !isNaN(parseFloat(variable)) && isFinite(variable) ) {
// Do something
}
@thekarel
thekarel / jsonio.js
Created July 21, 2013 23:22
JSON I/O
// From JSON
var jsObject = JSON.parse(jsonString);
// To JSON
var jsonString = JSON.stringify(foo);
@thekarel
thekarel / new_gist_file
Created August 8, 2013 10:29
Authentication in Apache ProxyPass
RequestHeader set Authorization "Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ=="
/*
* base64.js: An extremely simple implementation of base64 encoding / decoding using node.js Buffers
*
* (C) 2010, Nodejitsu Inc.
*
*/
var base64 = exports;
base64.encode = function (unencoded) {
RewriteRule \.(css|jpe?g|gif|png)$ - [L]
...
RewriteCond %{REQUEST_FILENAME} !-f
...
@thekarel
thekarel / new_gist_file
Created August 12, 2013 09:50
Tell David.js to generate request ("run") on page load From http://olivernn.github.io/davis.js/docs/
App.prototype.settings = {
linkSelector: 'a',
formSelector: 'form',
throwErrors: true,
handleRouteNotFound: false,
generateRequestOnPageLoad: true
};
<img class="hires" alt="" src="search.png" width="100" height="100" />
<script type="text/javascript">
$(function () {
if (window.devicePixelRatio == 2) {
var images = $("img.hires");
// loop through the images and make them hi-res
for(var i = 0; i < images.length; i++) {
@thekarel
thekarel / async-script-tag.js
Created August 20, 2013 09:30
Asyc loading script tag generating function
// Asynchronously load and execute a script from a specified URL
// Lifted from JavaScript: The Definitive Guide, 6th edition, p. 320
function loadasync(url) {
var head = document.getElementsByTagName("head")[0]; // Find document <head>
var s = document.createElement("script"); // Create a <script> element
s.src = url; // Set its src attribute
head.appendChild(s); // Insert the <script> into head
}
@thekarel
thekarel / inline-media-query.less
Created September 2, 2013 13:26
In-line media queries in LESS, with variables From http://lesscss.org/#-operations
// You can define variables to be used in media queries
@singleQuery: ~"(max-width: 500px)";
@media screen, @singleQuery {
set {
padding: 3 3 3 3;
}
}
// Which can lead to inline media queries that use variables for targets
@device1: ~'min-width: 768px AND max-width: 999px';