Skip to content

Instantly share code, notes, and snippets.

View jeffjohnson9046's full-sized avatar

Jefe Johnson jeffjohnson9046

View GitHub Profile
@jeffjohnson9046
jeffjohnson9046 / ImageSelectListItem.cs
Created August 16, 2012 19:00
Describes the ImageListItem class
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
namespace System.Web.Mvc.Html
{
public class ImageSelectListItem : SelectListItem
{
public string ImageFileName { get; set; }
@jeffjohnson9046
jeffjohnson9046 / ListItemToOption.cs
Created August 16, 2012 19:03
Describes how the title attribute is added to the option element
internal static string ListItemToOption(ImageSelectListItem item, string imagePath = "")
{
//if (!(item is ImageSelectListItem))
//{
// throw new InvalidCastException(string.Format("Cannot cast {0} to System.Web.Mvc.Html.ImageImageSelectListItem.", item.GetType()));
//}
//ImageSelectListItem imageImageSelectListItem = item as ImageSelectListItem;
TagBuilder builder = new TagBuilder("option")
@jeffjohnson9046
jeffjohnson9046 / ruby-ldap-sample.rb
Last active January 5, 2024 07:11
Some VERY basic LDAP interaction in Ruby using Net::LDAP.
#######################################################################################################################
# This Gist is some crib notes/tests/practice/whatever for talking to Active Directory via LDAP. The (surprisingly
# helpful) documentation for Net::LDAP can be found here: http://net-ldap.rubyforge.org/Net/LDAP.html
#######################################################################################################################
require 'rubygems'
require 'net/ldap'
#######################################################################################################################
# HELPER/UTILITY METHOD
@jeffjohnson9046
jeffjohnson9046 / will-paginate-ajax.js
Created October 22, 2013 00:02
How to "ajaxify" the control that will_paginate generates.
// "Ajaxify" the will_paginate control.
$(".pagination a").live("click", function() {
$(".pagination").html("Loading...");
$.getScript(this.href);
return false;
});
// For reference, here's what the html in the Rails view looks like:
// <div class="pagination pagination-centered">
// <%= will_paginate %>
@jeffjohnson9046
jeffjohnson9046 / gist:7996765
Created December 16, 2013 23:26
Use the command below to clean up MySQL whenever the host doesn't shut down gracefully
# If you see this error when trying to start MySQL: "Another MySQL daemon already running with the same unix socket.", run this to fix it:
sudo mv /var/lib/mysql/mysql.sock /var/lib/mysql/mysql.sock.bak
@jeffjohnson9046
jeffjohnson9046 / myapp.conf
Created January 9, 2014 20:50
An apache virtual host file for a Ruby on Rails app. Typically, this file will live in /etc/httpd/conf.d
<VirtualHost *:80>
ServerName # put my server name here
## Vhost docroot
DocumentRoot /path/to/app/root # if your app's root directory is /opt/myapp, this should be set to /opt
## Alias declarations for resources outside the DocumentRoot
Alias /myapp /path/to/app/public/directory # if your app's root directory is /opt/myapp this should be set to /opt/myapp/public
Alias /assets /path/to/app/public/assets/directory # if your app's root directory is /opt/myapp this should be set to /opt/myapp/public/assets
## Directories, there should at least be a declaration for /opt/myapp/public
@jeffjohnson9046
jeffjohnson9046 / passenger.conf
Created January 9, 2014 20:54
An example passenger.conf file for setting up a Rails app to run in Phusion Passenger.
# The Passanger Apache module configuration file is being
# managed by Puppet and changes will be overwritten.
<IfModule mod_passenger.c>
PassengerRoot /usr/local/rvm/gems/ruby-1.9.3-p484/gems/passenger-3.0.21
PassengerRuby /usr/local/rvm/wrappers/ruby-1.9.3-p484/ruby
PassengerMaxPoolSize 30
PassengerPoolIdleTime 300
PassengerDefaultUser appuser # set this to whoever owns the directories for your Rails app
</IfModule>
@jeffjohnson9046
jeffjohnson9046 / percent-filter.js
Last active September 4, 2020 23:25
Format percentages in AngularJS
// In app.js or main.js or whatever:
// var myApp = angular.module('askchisne', ['ngSanitize', 'ngAnimate', 'ui.bootstrap', 'ui.bootstrap.tpls']);
// This filter makes the assumption that the input will be in decimal form (i.e. 17% is 0.17).
myApp.filter('percentage', ['$filter', function ($filter) {
return function (input, decimals) {
return $filter('number')(input * 100, decimals) + '%';
};
}]);
@jeffjohnson9046
jeffjohnson9046 / title-case-filter.js
Created March 26, 2014 18:22
A title-case filter for AngularJs
// Came from the comments here: https://gist.github.com/maruf-nc/5625869
app.filter('titlecase', function() {
return function (input) {
var smallWords = /^(a|an|and|as|at|but|by|en|for|if|in|nor|of|on|or|per|the|to|vs?\.?|via)$/i;
input = input.toLowerCase();
return input.replace(/[A-Za-z0-9\u00C0-\u00FF]+[^\s-]*/g, function(match, index, title) {
if (index > 0 && index + match.length !== title.length &&
match.search(smallWords) > -1 && title.charAt(index - 2) !== ":" &&
(title.charAt(index + match.length) !== '-' || title.charAt(index - 1) === '-') &&
@jeffjohnson9046
jeffjohnson9046 / td-hover-test.html
Created May 7, 2014 15:43
TD Hover - Different Color for Each Column. Seems to work for all major browsers (IE8+)
<!DOCTYPE html>
<html>
<head>
<title>Table Hover CSS Test</title>
<style>
th {
font-weight: bold;
font-size: 16px;
text-align: center;
}