Skip to content

Instantly share code, notes, and snippets.

@mfr
mfr / urlParams.js
Created October 10, 2011 12:35
url parameters - javascript
var urlParams = {};
(function () {
var e,
r = /([^&=]+)=?([^&]*)/g,
d = function (s) { return decodeURIComponent(unescape(s)); },
q = window.location.search.substring(1);
while (e = r.exec(q))
urlParams[d(e[1])] = d(e[2]);
})();
@mfr
mfr / gist:1275370
Created October 10, 2011 13:45
MySQL selecting random rows fast
SELECT *
FROM (
SELECT @cnt := COUNT(*) + 1,
@lim := 10
FROM t_random
) vars
STRAIGHT_JOIN
(
SELECT r.*,
@lim := @lim - 1
@mfr
mfr / gist:1281094
Created October 12, 2011 12:25
unique value
CREATE TABLE `some_table` (
 `id` int(4) unsigned NOT NULL AUTO_INCREMENT,
 `value` varchar(255) NOT NULL DEFAULT '',
 PRIMARY KEY (`id`),
 UNIQUE KEY `value` (`value`)
);
INSERT INTO some_table (value) VALUES ('test') ON DUPLICATE KEY UPDATE id = LAST_INSERT_ID(id);
select last_insert_id();
@mfr
mfr / netatmo_pws.php
Created December 23, 2012 10:56
Reading last data from netatmo device and sending it to wunderground.
#!/usr/bin/php
<?php
date_default_timezone_set('UTC');
/**
* oAuth settings from http://dev.netatmo.com/dev/listapps
*/
define('APP_ID', '');
define('APP_SECRET', '');
define('USERNAME', '');
define('PASSWORD', '');
@mfr
mfr / pxs.java
Last active December 17, 2015 09:59
import javax.swing.*;
import java.awt.*;
import java.awt.image.BufferedImage;
public class pxs extends JFrame {
private static final long SLEEP_DELAY = 500L;
private static JLabel label;
public static void main(String[] args) {
JFrame frame = new pxs();
#!/bin/bash
for f in *.css; do
grep -ioE "(url\(|src=)['\"]?[^)'\"]*" $f | grep -ioE "[^\"'(]*.\.(woff)" | while read l ; do
sed -i "s>$l>data:font/${l/[^.]*./};base64,`openssl enc -base64 -in $l| tr -d '\n'`>" $f ;
done;
done;
@mfr
mfr / check.sh
Created June 3, 2013 14:10
Script that checks whether lighttpd is still up, and if not: - e-mail the last bit of log files - kick some life back into it
#!/bin/bash
# Script that checks whether lighttpd is still up, and if not:
# - e-mail the last bit of log files
# - kick some life back into it
# -- Thomas, 20050606
PATH=/bin:/usr/bin
THEDIR=/tmp/lighttpd-watchdog
EMAIL=
PATH=
export PATH=/usr/local/bin:/usr/local/sbin:$PATH
[ -z "$PS1" ] && return
export TERM=xterm-color
export CLICOLOR=1
export LSCOLORS=GxFxCxDxBxegedabagaced
#export PS1="\h:\W \u\$"
#export PS1="[\u@\[\e[32;1m\]\H \[\e[0m\]\w]\$ "
#export PS1="\h:\[\e[32;1m\]\W\e[0m\] \$ "
#alias ll='ls -hl'
var page = require('webpage').create(),
address, output, size;
if (phantom.args.length < 2 || phantom.args.length > 3) {
console.log('Usage: rasterize.js URL filename');
phantom.exit();
} else {
address = phantom.args[0];
output = phantom.args[1];
page.viewportSize = { width: 1280, height: 1024 };
@mfr
mfr / screencap.js
Last active December 28, 2015 05:39
var page = require('webpage').create();
var system = require('system');
var cur_date = new Date();
var folder = cur_date.getFullYear() + '-' + (cur_date.getMonth()+1) + '-' + cur_date.getDate();// +'_'+ cur_date.getHours() +cur_date.getMinutes();
var url = system.args[1];
var filename = url.replace(/[^a-z0-9]/gi, '_').toLowerCase();
page.open(url, function () {
page.render(folder+'/'+filename+'.png');