Cronic, fixing excessive cron emails

Earlier today I found a very very useful program to help cut down in the massive amount of spam system administrators receive from cron emails. I decided to create a simple installer for it. Check out cronic at http://habilis.net/cronic/. To install automatically to your system, just run this command as root.

wget http://mrkmg.com/install_cronic.sh -qO - | sh

There is no error checking in the installer, use at your own risk.

 

install_cronic.sh for your reference if you do not want to trust running a shell script from the internet.

#!/bin/sh
mkdir /tmp/cronic
echo "Downloading Cronic from habilis.net"
wget http://habilis.net/cronic/cronic -qO - > /tmp/cronic/cronic
echo "Installing Cronic into /var/local/cronic/cronic"
mkdir -p /var/local/cronic/
cp /tmp/cronic/cronic /var/local/cronic/cronic
chmod 777 /var/local/cronic/cronic
echo "Linking Cronic into /usr/bin"
ln -s /var/local/cronic/cronic /usr/bin/cronic
echo "Cronic is installed and ready to be used. Checkout"
echo "http://habilis.net/cronic/ for more information."
echo "Installer created by Kevin Gravier <[email protected]>"

Simple Floating Clock for Linux CLI (tclock)

I found a very nice and easy to use script to place a floating clock on your CLI in linux.

wget https://gist.github.com/raw/2713194/cb9eb0426dc81f3411c7bb2e592963378bb3b2d7/tclock.sh
chmod 755 tclock.sh
./tclock.sh&
#!/bin/sh

### Floating Clock ######################################################
# Created by Scott Garrett https://github.com/Wintervenom #
# Found via https://bbs.archlinux.org/viewtopic.php?pid=557778#p557778 #
# Maintained By Kevin Gravier <[email protected]> #
#########################################################################

cols=`tput cols`

touch /tmp/tclock.run
while [ -e /tmp/tclock.run ]; do
tput sc
  tput cup 0 $((cols - 13))
  printf " $(date +%r) "
  tput rc
  sleep 1
done

view raw tclock.sh This Gist brought to you by GitHub.

Update to AxelFE, no more console

Quick update to AxelFE, no more console! Everything is now contained and run in the GUI. Check out the new version. http://mrkmg.com/?page_id=79

Axel Download Accelerator for Windows – with Graphical Frontend

So a while back I showed you how to speed up your downloads for free on OSX with Axel and a simple applescript. Well it looks like someone has compiled Axel on Windows (http://st0rage.org/~n2j3/?page_id=225717166) . I went ahead and created a very simple frontend for it. Feel free to download and try it out.

**EDIT 2/15/2012** I updated the frontend to look a little better, added a title and got rid of the the program icon. Also defaults are now set and if you have a valid URL in your clipboard it will automatically paste it into the URL field. I also created a simple installer. Nothing extra in there either, no ads, no bloatware, no spyware, etc.

http://mrkmg.com/Axel.zip  — No-Installer, Launch “Axel Front End.exe” to Run
http://mrkmg.com/AxelFE.zip — Installer – zipped – No Bloatware, No Ads. Just a simple installer.
http://mrkmg.com/AxelFE.7z – Installer – 7zipped – No Bloatware, No Ads. Just a simple installer.

PHP function to generate a color from a text string

So I was in need of a way to generate a unique color based on a string input. I wanted to be able to define a minimum brightness and how unique each color should be. After a little googleing, I did not find anything I liked, so I wrote my own real quick. Hopefully someone else can find a use for this function as well

<?php
/*
* Outputs a color (#000000) based Text input
*
* @param $text String of text
* @param $min_brightness Integer between 0 and 100
* @param $spec Integer between 2-10, determines how unique each color will be
*/

function genColorCodeFromText($text,$min_brightness=100,$spec=10)
{
// Check inputs
if(!is_int($min_brightness)) throw new Exception("$min_brightness is not an integer");
if(!is_int($spec)) throw new Exception("$spec is not an integer");
if($spec < 2 or $spec > 10) throw new Exception("$spec is out of range");
if($min_brightness < 0 or $min_brightness > 255) throw new Exception("$min_brightness is out of range");


$hash = md5($text); //Gen hash of text
$colors = array();
for($i=0;$i<3;$i++)
$colors[$i] = max(array(round(((hexdec(substr($hash,$spec*$i,$spec)))/hexdec(str_pad('',$spec,'F')))*255),$min_brightness)); //convert hash into 3 decimal values between 0 and 255

if($min_brightness > 0) //only check brightness requirements if min_brightness is about 100
while( array_sum($colors)/3 < $min_brightness ) //loop until brightness is above or equal to min_brightness
for($i=0;$i<3;$i++)
$colors[$i] += 10; //increase each color by 10

$output = '';

for($i=0;$i<3;$i++)
$output .= str_pad(dechex($colors[$i]),2,0,STR_PAD_LEFT); //convert each color to hex and append to output

return '#'.$output;
}
?>

Updates to jquery onHold plugin

I have made some updates to the jquery onhold plugin. I also added it on github. The updates include

  • Default setting
  • Supports more than one selector
  • Easier ability to add in more options, if ever needed (I have some ideas)

 

 

Github: https://github.com/mrkmg/jquery.onHold

 

DEMO: http://jsfiddle.net/bCgWW/

Updated Code:

/*
This is free software, its code can be redistributed and/or modified at will for any purpose. Just leave this header here. Thanks
--MrKmg
*/

/*

Options:

	time: 	Period of time a user should have to hold their mouse button down on an object to fire the event;
			Measured in Milliseconds
			Defaults to 5000
*/

(function( $ ){
    $.fn.onHold= function(callback,options) {

		var settings = $.extend({
			time:5000
		},options);

		return this.each(function(){
			var $this = $(this);
			$this.data('onHold_selected',false);
			$this.mousedown(function(){
				$this.data('onHold_selected',true);
				setTimeout(function(){
					if($this.data('onHold_selected')){
						 callback();
					}
				},settings.time);
			});
			$this.mouseup(function(){
				$this.data('onHold_selected',false);
			});
		});

    };
})( jQuery );

 

 

 

 

Use jQuery UI to pretty up the standard Javascript alert()

So I was working on a project that had many calls to the standard Javascript alert(). I wanted to pretty up those alerts without re-writing each one. Since I was already using jQuery and jQuery UI in the project, I decided I could convert all the alerts to jQuery UI Dialog Boxes.

Its a pretty simple process. First you create an empty div and give it a unique ID.

<div id="override_javascript_alert"></div>

Next we need to override the window.alert function.

<div id="override_javascript_alert"></div>

<script>
window.alert = function(message) {
};
</script>

Finally, all in one swoop we can put our message in the div and turn it into a jQuery UI Dialog with an OK button.

<div id="override_javascript_alert"></div>

<script>
window.alert = function(message) {
	$('#override_javascript_alert').text(message).dialog({
		modal:true,
		title:'Message',
		buttons: {
			'OK':function(){
				$(this).dialog('close');
			}
		}
	});
};
</script>

Hope you find this as useful as I did. You can add more parameters to the alert option and offer more customization.

Jquery Plugin: onHold Event

This simple plugin adds the following event:

.onHold(time,action);

See this for a working example:
http://jsfiddle.net/hkBfP/

(function( $ ){
    $.fn.onHold= function(time,action) {
        this.data('onHold_selected',false);
        this.mousedown(function(){
            $(this).data('onHold_selected',true);
            var object = this;
            setTimeout(function(){
                if($(object).data('onHold_selected')){
                     action();
                }
            },time);
        });
        this.mouseup(function(){
            $(this).data('onHold_selected',false);
        });
       return this;
    };
})( jQuery );

OpenData Project

I have started a project I call the OpenData Project. To sum it up it is a free, open API that serves as a simple Key/Value server. The API is easy to understand, and can be accessed from anything that can make http calls. There is no signup, no registration,  no fees, nothing. Just use it. I have provided a simple implementation of the API in php, but it is easily portable to any other language.

How it works

As a user, you start by creating a new table. To do this you must pass the  new query and a tablename. This can be done via GET or POST, but for simplicity sake I will only show you GET examples here. To start a new table, you would do this:

http://kevingravier.com/opendata/api.php?q=new&name=test

Create new table

This will return a plaintext answer. If there were no problems it will be 3 lines. The first line is the result code. A 0 inplies there was an error, a 1 implies there was no problems. If you get a 1, as you should, the next line will be your secret key. You must save this because it is required to use your table. The third line should be the name of the table you sent to OpenData. Below is an example of a new query’s result.

1
618f1323ad3e7c7b376e1e79e13e0ee6
test

Add a new key

From here you can add data to your table. This can be achieved by sending the add query along with the table name, the secret key for that table, the key name, and the value you want to save.

http://kevingravier.com/opendata/api.php?q=add&name=test&secret=618f1323ad3e7c7b376e1e79e13e0ee6&key=test&value=bla

The result again will have a 1 or 0 on the first line, 1 for success and 0 for failure. Here is the result from the previous query.

1
test
bla

Edit an existing key

As you can see the request was successful and it returned the key and value. Once keys are added, you obviously can edit them. the query is almost the same as the add but just change the word add to edit.

http://kevingravier.com/opendata/api.php?q=edit&name=test&secret=618f1323ad3e7c7b376e1e79e13e0ee6&key=test&value=blabla

Now the Key test has the value blabla. Here is the result from that.

1
test
blabla

List all existing keys

You can see the result is the same format every time. Now lets say we want to see all the keys that are on the table test, I have added a few extras already, they were test2, and hello. You can just run the list query. Remember you still have to give the table name and secret key.

http://kevingravier.com/opendata/api.php?q=list&name=test&secret=618f1323ad3e7c7b376e1e79e13e0ee6

The result follows the same pattern. The first line will be a 1 or 0. If it is a 1 each following line will contain one key.

1
test2
test
hello

View the value for a key

To view the value of any key, just use the view query.

http://kevingravier.com/opendata/api.php?q=view&name=test&secret=618f1323ad3e7c7b376e1e79e13e0ee6&key=test

With the result:

1
blabla

Delete a key

To delete a key, and its corresponding value, you can use the delete query. Lets delete the key test2.

http://kevingravier.com/opendata/api.php?q=delete&name=test&secret=618f1323ad3e7c7b376e1e79e13e0ee6&key=test2

With a simple result:

1
test2

Remove a table

And finally to remove the entire table, including the secret key associated with it, use the remove query.

http://kevingravier.com/opendata/api.php?q=remove&name=test&secret=618f1323ad3e7c7b376e1e79e13e0ee6

And the result of the remove is:

1
test
618f1323ad3e7c7b376e1e79e13e0ee6

Handle errors

It gives you the table name and the secret key that was linked to it. Every error is returned as follows:

0
error_number
description of error

I will post a list of what each error number means at a later time. I have also written a sample OpenData class you can use to access the OpenData server easily. I wrote this is php and also plan of porting it to perl and python. Here is that code:http://kevingravier.com/opendata/sample.txt. Any question, comments, or concerns can be sent to me via email: kevin at mrkmg dot com or posted as a comment here. Thanks, Kevin Gravier (MrKMG).