Skip to content

Instantly share code, notes, and snippets.

View stevelippert's full-sized avatar

Steve Lippert stevelippert

View GitHub Profile
@stevelippert
stevelippert / humanReadable.pl
Created June 9, 2014 17:53
Two different functions to generate human readable bytes.
#OLD
sub humanBytes {
my $bytes = shift(@_);
if ($bytes > 1125899906842624){
return sprintf("%.2f Pb", $bytes / 1125899906842624);
}elsif ($bytes > 1099511627776){
return sprintf("%.2f Tb", $bytes / 1099511627776);
}elsif ($bytes > 1073741824){
return sprintf("%.2f Gb", $bytes / 1073741824);
}elsif ($bytes > 1048576){
@stevelippert
stevelippert / getUTCTimestamp.pl
Created June 30, 2014 14:06
getUTCTimestamp: A subroutine to return an epoch time stamp for UTC time.
sub getUTCTimestamp {
my ($localTime, @t, $offset);
$localTime = time;
@t = localtime(time);
$offset = timegm(@t) - timelocal(@t);
$offset =~ s/\-//g;
return ($localTime + $offset);
}
@stevelippert
stevelippert / first_input_class.js
Created January 6, 2015 16:49
jQuery: Finding the first input with a class
$("form").find("input[type=text]").filter(".YOUR-CLASS-HERE:visible:first").focus();
<script charset="utf8" src="/libs/js/jquery.hotkeys.min.js"></script>
//When the ALT + N keys are pressed together, trigger the button click (as it has additional logic to process).
$(document).on("keydown", null, "alt+n", function(){
$("#BUTTON_ID").trigger("click");
});
@stevelippert
stevelippert / jquery_bad_counting_matching_elements.js
Created February 27, 2015 16:21
An example of bad code to count the number of matching elements on a page.
function countFlaggedQs(){
var fgC = 0,
fgT = ' flagged questions';
$(".q-flag").each(function(){
if( $(this).children(".icon-flag").length ) {
fgC++;
}
});
fgT = (fgC === 1) ? ' flagged question' : ' flagged questions';
$("#q_fg").html( fgC+' <i class="icon-flag" title="'+fgC+fgT+'"></i>' );
@stevelippert
stevelippert / jquery_good_counting_matching_elements.js
Created February 27, 2015 16:25
An example of good counting of a matching element on the page
function countFlaggedQs(){
var fgC = $(".q-flag").children(".icon-flag").length,
fgT = ' flagged questions';
fgT = (fgC === 1) ? ' flagged question' : ' flagged questions';
$("#q_fg").html( fgC+' <i class="icon-flag" title="'+fgC+fgT+'"></i>' );
}
@stevelippert
stevelippert / README.md
Last active August 29, 2015 14:19 — forked from hofmannsven/README.md
A simple help document for git.
@stevelippert
stevelippert / fullCalendar_init.js
Last active May 17, 2018 06:44
FullCalendar.js - Example Initialization (http://fullcalendar.io)
calendar = $('#calendar').fullCalendar({
defaultView: "agendaWeek",
header: {
left: 'prev,next today',
center: 'title',
right: 'month,agendaWeek,agendaDay'
},
buttonText: {
today: "Today",
month: "Month",
@stevelippert
stevelippert / eventRender.js
Created June 3, 2015 16:19
FullCalendar.js - eventRender example
eventRender: function(event, element) {
if ( event.user ) {
element.find(".fc-title").append(" (" + event.user + ")");
}
//console.dir(element);
}
@stevelippert
stevelippert / s3_upload.pl
Created October 12, 2016 19:22
An example of uploading a local file to S3.
#!/usr/bin/perl
use warnings;
use strict;
use Amazon::S3;
use vars qw/$OWNER_ID $OWNER_DISPLAYNAME/;
my $aws_access_key_id = 'YOUR AWS ACCESS KEY HERE';
my $aws_secret_access_key = 'YOUR AWS SECRET ACCESS KEY HERE';