Skip to content

Instantly share code, notes, and snippets.

View scottoffen's full-sized avatar
💭
Live in SLC

Scott Offen scottoffen

💭
Live in SLC
View GitHub Profile
@scottoffen
scottoffen / timezones-snippet.html
Last active August 29, 2015 13:57
HTML Select Timezone or MySQL
<!--
mysql query to generate option list
SELECT CONCAT('<option value="', `Name`, '">', `Name`, '</option>') FROM mysql.time_zone_name;
if mysql.time_zone_name has no records go here: http://dev.mysql.com/downloads/timezones.html
to convert date/time between timezones do something like this:
SELECT startdate, CONVERT_TZ(startdate, 'utc', (SELECT timezone FROM accounts WHERE id=1)) FROM auctions;
This query takes two values, one on daylight savings and one off daylight savings, and converts them to a daylight savings impacted time zone:
@scottoffen
scottoffen / backup-restore-mysql.sql
Created April 12, 2014 22:51
Backup and Restore MySQL Databases
mysqldump -u [username] -p [schema] > filename_yyyy.mm.dd.sql
mysql -u [username] -p [schema] < filename_yyyy.mm.dd.sql
-- You will be prompted to provide the password each time
@scottoffen
scottoffen / export-mysql-schema.sql
Created April 12, 2014 23:40
Export MySQL Schema
-- You will be prompted for a password as necessary
mysqldump -u [username] -p [schema] --no-data > schema.sql
@scottoffen
scottoffen / parsemime.pl
Last active August 29, 2015 14:00
Perl parses the Apache mime.types file for use in ContentTypes.cs (https://gist.github.com/scottoffen/11197961)
#!/usr/bin/perl
use strict;
use warnings;
# input file taken from:
# http://svn.apache.org/repos/asf/httpd/httpd/trunk/docs/conf/mime.types
my %extensions;
my $input = "./mimetypes.txt";
my $output = "./contenttypes.txt";
@scottoffen
scottoffen / parsemergemime.pl
Created April 23, 2014 16:59
Perl parse and merge Apache mime.types and a list from StackOverflow to genereate ContentType.cs (https://gist.github.com/scottoffen/11197961)
#!/usr/bin/perl
use strict;
use warnings;
#----------------------------------------------------------------------------------#
# Run from the command line. This will first parse the Apache mime.types file from #
# here (http://svn.apache.org/repos/asf/httpd/httpd/trunk/docs/conf/mime.types), #
# and then the dictionary portion only of this (http://stackoverflow.com/a/7161265)#
# StackOverflow answer (starting on the fifth line down), saved as mime.dict. All #
# files are expected to be in the same directory. #
@scottoffen
scottoffen / StringExtensions.cs
Last active August 29, 2015 14:00
My favorite C# string extension methods!
using System;
using System.Text.RegularExpressions;
namespace YourNamespace
{
public static class StringExtensions
{
public static string Capitalize(this String s)
{
if (!String.IsNullOrEmpty(s))
@scottoffen
scottoffen / ExtendedRestServer.cs
Created May 1, 2014 17:53
Grapevine.RestServer Extensions for JSON Request/Responses
using System;
using System.IO;
using System.Net;
using System.Text;
using Grapevine;
using Newtonsoft.Json.Linq;
namespace YourNameSpace
{
class ExtendedRestServer
@scottoffen
scottoffen / declassify.pl
Last active August 29, 2015 14:01
Declassify arguments to a perl exported/static method
use Scalar::Util ('blessed');
###############################| Declassify |###############################
sub Declassify
{
my @params = @_;
shift (@params) if ($params[0] eq __PACKAGE__);
my @args = (ref $params[0] eq 'ARRAY') ? @{$params[0]} : ();
my $pkg = $params[1] || __PACKAGE__;
@scottoffen
scottoffen / CommandLine.java
Created June 7, 2014 00:18
Java Command Line Made Easy
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class CommandLine
{
private static final BufferedReader input;
static
{
input = new BufferedReader(new InputStreamReader(System.in));
@scottoffen
scottoffen / layers.html
Created June 30, 2014 16:54
HTML CSS Layers Example
<!doctype html>
<html lang=en>
<head>
<meta charset=utf-8>
<title>Layers</title>
<style type="text/css">
#loading, #loaded
{
position: fixed;