Skip to content

Instantly share code, notes, and snippets.

View stevelippert's full-sized avatar

Steve Lippert stevelippert

View GitHub Profile
@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();
@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 / 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 / weatherstem_api.rb
Created May 12, 2014 00:58
WeatherSTEM API Example in Ruby
#!/usr/bin/env ruby
require 'uri'
require 'json'
require 'net/http'
require 'net/https'
uri = URI.parse("https://leonschools.weatherstem.com/api")
https = Net::HTTP.new(uri.host, uri.port)
https.use_ssl = true
@stevelippert
stevelippert / weatherstem_api.go
Created May 12, 2014 00:11
WeatherSTEM API Example in Go
package main
import (
"net/http"
"strings"
"io/ioutil"
"fmt"
"crypto/tls"
)
@stevelippert
stevelippert / weatherstem_api.php
Created May 10, 2014 18:54
WeatherSTEM PHP API Example
<?php
$url = 'https://leonschools.weatherstem.com/api';
$vars = array(
"stations" => array("canopyoaks"),
"api_key" =>"cs9ynb6t"
);
$options = array(
'http' => array(
@stevelippert
stevelippert / append_option_select_list.js
Created April 29, 2014 14:21
Adding options to a select list in jQuery
$("#yourIDHERE").append('<option value="something">Your text here</option>');
$("#yourIDHERE").append( $("<option/>", {value: "something", text: "Your text here"}) );
$("#yourIDHERE").append('<option value="gte">&ge;</option>');
$("#yourIDHERE").append( $("<option/>", {value: "gte", html: "&ge;"}) );
@stevelippert
stevelippert / test.log
Created March 10, 2014 17:47
Sample output from worker.pl
53440 - Mon Mar 10 13:38:19 2014 sleeping for: 60
53436 - Mon Mar 10 13:38:27 2014 sleeping for: 83
53440 - Mon Mar 10 13:39:19 2014 sleeping for: 0
53440 - Mon Mar 10 13:39:19 2014 sleeping for: 23
53440 - Mon Mar 10 13:39:42 2014 sleeping for: 91
53436 - Mon Mar 10 13:39:50 2014 sleeping for: 28
53436 - Mon Mar 10 13:40:18 2014 sleeping for: 38
53436 - Mon Mar 10 13:40:56 2014 sleeping for: 86
@stevelippert
stevelippert / ubic_test_worker
Created March 10, 2014 17:46
A simple Ubic Multiservice initialization script
use Ubic::Multiservice::Simple;
use Ubic::Service::SimpleDaemon;
return Ubic::Multiservice::Simple->new({
map { (
"worker$_" => Ubic::Service::SimpleDaemon->new({
bin => "/home/steve/worker.pl",
})
)}(1..2)
});
@stevelippert
stevelippert / worker.pl
Last active August 29, 2015 13:57
A simple 'worker' script that write to a log every RAND seconds.
#!/usr/local/bin/perl
my $outputFile = '/home/steve/test.log';
while (1){
my $sleepTime = int( rand( 120 ) );
open my $fh, '>>', $outputFile;
print $fh $$." - ".localtime." sleeping for: ".$sleepTime."\n";
close $fh;
sleep( $sleepTime );