Skip to content

Instantly share code, notes, and snippets.

View mrkmg's full-sized avatar

Kevin mrkmg

View GitHub Profile
@mrkmg
mrkmg / jquery.onhold.js
Created October 4, 2011 20:21
jQuery On Hold event
(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();
}
@mrkmg
mrkmg / genColorCodeFromText.php
Created January 13, 2012 17:22
Generate a unique color based on text input
<?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)
@mrkmg
mrkmg / axel.scpt
Created February 13, 2012 21:17
AXEL Apple Script
--Written by Kevin Gravier
--Edit and redistribute as you please but leave this header.
property lastURL : "http://link.to.file"
property lastThreads : 4
set link to text returned of (display dialog "What do you want to download?" buttons {"OK"} default button 1 default answer lastURL with icon 1)
set lastURL to link
set threads to text returned of (display dialog "How many threads?" buttons {"OK"} default button 1 default answer lastThreads with icon 1)
set lastThreads to threads
@mrkmg
mrkmg / JApi.php
Created May 11, 2012 14:08
JApi, short for JSON API, is an action handler for Yii.
<?php
/**
* JApi, short of JSON API, is an action handler for Yii.
*
* JApi maps requests in the form ?r=controller/japu&action=method to controller->japiMethod. Then, anything returned from
* japiMethod is encoded in JSON and sent to the client. Parameters in the function are mapped to _GET varibles. JApi
* follows the requirments of the parameters, such as optional and required.
*
* EXAMPLE:
in ExampleController.php
@mrkmg
mrkmg / tclock.sh
Created May 16, 2012 19:17
Floating Clock for linux (tclock)
#!/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 <kevin@mrkmg.com> #
#########################################################################
cols=`tput cols`
@mrkmg
mrkmg / TPM.php
Last active October 10, 2015 19:59
Tick Per Minute Class. You can add a tick at anytime, and then later calculate the average ticks per min
<?php
class TPM {
public $useCtime = true; //If true, use current time for tpm calculation. If false, use last tick.
public $purgeOlderThan = 15; //Time in minutes to purge old data
private $ticks = array();
//Add a tick
public function tick(){
@mrkmg
mrkmg / numweekendsbyyear.php
Created December 10, 2012 22:17
Calculate number of weekends per month, quarter, and year
#!/usr/bin/env php
<?php
if(!isset($argv[1]) or !is_numeric($argv[1]) or strlen($argv[1]) != 4){
$cmd = $argv[0];
echo <<<out
See the number of weekend in each month, quarter, and yearly.
Usage: $cmd yyyy
$types = array(
'ai' => 'application/postscript',
'aif' => 'audio/x-aiff',
'aifc' => 'audio/x-aiff',
'aiff' => 'audio/x-aiff',
'asc' => 'text/plain',
'atom' => 'application/atom+xml',
'atom' => 'application/atom+xml',
'au' => 'audio/basic',
'avi' => 'video/x-msvideo',
@mrkmg
mrkmg / extractIcoFromExe.php
Last active February 28, 2017 02:31
PHP Code snippet to extract the icon from an exe file on a Linux system as a png -- tested on Debian Wheezy
<?php
// Code snippet to extract the icon from an exe file on a Linux system -- tested on Debian Wheezy
// Install icoutils on your system e.g. sudo apt-get install icoutils
// Web process must have write privileges to /tmp
///** Config **///
$input_file = '/path/to/program.exe';
@mrkmg
mrkmg / niceness_lower.php
Last active December 17, 2015 01:59
PHP5 snippit to lower threads niceness and then kill the thread when finished.
<?php
proc_nice(19); //Lowers niceness
set_time_limit(0); //Removes timelimit of script
/****
...
Do some very intensive task you do not want to bog down your server
...
****/