Skip to content

Instantly share code, notes, and snippets.

@starstuck
starstuck / raspberrypi-dht11.py
Created October 30, 2015 12:14
Read humidity and temperature from DHT11 sensor connected to RaspbberyPi
#!/usr/bin/env python
# -*- coding: utf8 -*-
#
# Read humidity and temperature from DHT11 sensor connected to RaspberryPi.
#
# DHT11 protocol depends on exact timing. Sometimes linux kernel may evict your
# process, or GC can cause program to miss some of a bits from transmission. In
# that case following application will raise an error and you can try to run it
# again
#
@starstuck
starstuck / esi-server.js
Last active December 17, 2015 16:19
Simple server expanding esi:include tags from local html files. Very usefull to test your static pages before uploading to Akamai. Written in node.js.
/**
* Simple server expanding esi:include tags from local html files.
* Very usefull to test your static pages before uploading to Akamai.
*
* $ npm install express
*
* Now you are ready to run preview server:
*
* $ node esi-server.js
*
@starstuck
starstuck / jstags.sh
Created July 19, 2013 17:16
Build etags from javascript files including names exposed using global namespace convention and properties assigned to prototype
#!/usr/bin/env sh
SYMBOL="[a-zA-Z_][a-zA-Z0-9_]*"
CAP_SYMBOL="[A-Z][a-zA-Z0-9_]*"
GLOB_SYMBOL="${CAP_SYMBOL}\(\.${SYMBOL}\)*"
if [ -z "$1" ]; then
echo "You need to provide at list one path where to search for js files" 1>&2
exit 1
fi
@starstuck
starstuck / build.js
Created July 25, 2013 07:20
Example of maven project using npm for managing js dependencies, lessc for CSS preprocessing and r.js for js modules assembly.
#!/usr/bin/env node
var exec = require('child_process').exec,
mkdirp = require('mkdirp'),
projectPath = __dirname + '/../..',
targetPath = __dirname + '/../../target/assets';
// Task execution helpers
// ----------------------
@starstuck
starstuck / run-jasmine-in-mocha.js
Last active December 20, 2015 05:19
Running jasmine tests in phantom while sending results back to mocha on node to have nice console reporter
#!/usr/bin/env node
var server = require('./test-server'),
child_process = require('child_process'),
port = server.port;
console.log('');
console.log('------------------------------------------------------------------------');
console.log('Running jasmine tests in phantomjs');
@starstuck
starstuck / emacs.el
Created September 4, 2013 18:02
Add compilation-error-regexp to make Emacs recognize jstestdriver and jslint output
;; Define various js test/linting compilation errrors matchers. You can say,
;; which you want to consider on matching output from compilation, by
;; customizing compilation-error-regexp-alist variable.
;;
;; (setq compilation-error-regexp-alist (list 'jstestdriver 'jslint-file 'jslint-line))
;;
;; If you are using desktop.el, you may want to keep compilation customizations
;; in your project deskto file
;;
;; (add-to-list 'desktop-globals-to-save 'compilation-search-path)
@starstuck
starstuck / text-outline.svg
Created October 9, 2013 08:47
Svg text outline using filters
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@starstuck
starstuck / proxy.js
Created November 1, 2013 15:05
Simple forward proxy in node.js, which intercept calls and let you add custom scripts to live sites/web apps. In this example it is adding skewer script, so you can mess around with live pages from emacs.
/**
* To run it you will need to install
*
* $ npm install http-proxy
*/
var http = require('http'),
httpProxy = require('http-proxy'),
port = 3001,
proxiedHost = 'localhost',
@starstuck
starstuck / debug-proxy.js
Last active December 30, 2015 12:19
Proxy setup for developing and debugging web applications. It creates node.js servercombining express + http-proxy to provide uncompressed JS and CSS over proxied live content. It works very well with source maps.
/**
* Web application debug proxy server.
*
* It is suited for hosting uncompressed sources of front-end assets and proxy dynamic
* requests to servers preparing data. I find similar setup also useful for investigating
* issues on production servers by going through the proxy, which use local unminified
* JS and CSS on top of production html pages.
*
* To run following example you will need to have http-proxy, express and send packages installed.
*
@starstuck
starstuck / git-svn-fix-tags.sh
Last active January 2, 2016 09:18
Convert all git-svn pseudo tag branches to proper tags.
#!/usr/bin/env bash
#
# Following script will work with tags preficed with svn, having mapping like:
# tags = project/tags/*:refs/remotes/svn/tags/*
# If you use differnet paths mapping, you may need to adjust it a bit.
#
git for-each-ref --shell --format='parent=%(parent) refname=%(refname)' refs/remotes/svn/tags/ | \
while read entry
do