Skip to content

Instantly share code, notes, and snippets.

View jbnv's full-sized avatar
🙂
Life is good.

Jay Bienvenu jbnv

🙂
Life is good.
View GitHub Profile
@jbnv
jbnv / ddmenu.html
Last active August 27, 2015 14:58
Dropdown Menu Bar/Ribbon in Bootstrap
<nav class="main-nav dropdown">
<ul class="list-inline">
<li id="liSort">
<button class="btn btn-link" data-toggle="dropdown">
<i class="fa fa-sort-amount-asc"></i>
<span class="hidden-xs">Sort</span>
<span class="caret"></span>
</button>
<ul class="dropdown-menu" role="menu" aria-labelledby="liSort">
<li role="presentation"><a role="menuitem" tabindex="-1">Sort Option 1</a></li>
@jbnv
jbnv / English Names Query
Created June 2, 2015 00:45
Query to generate a number of English names for data mocking
/*
The referenced views (which could also be tables) are one-column views
(or tables) that contain instances of the particular type of name. For
[EnglishMaleFirstNameView] and [EnglishFemaleFirstNameView], the one
column must be named [Name]. For [EnglishSurnamePrefixView], the one
column must be named [Prefix]. This view can contain surnames that would
otherwise stand alone. For [EnglishSurnameSufffixView], the one column
must be named [Suffix]. Each element of this list must not be
capitalized. This list should contain an empty string element so that
the prefix can stand alone. Examples of each of these views are
@jbnv
jbnv / Split Function
Created June 2, 2015 00:48
Function for SQL Server that splits a delimited string into a table of items.
CREATE FUNCTION [dbo].[Split] (
@List nvarchar(MAX),
@Delimiter nvarchar(3)
)
RETURNS TABLE
WITH SCHEMABINDING
AS
RETURN (
SELECT ROW_NUMBER() OVER(ORDER BY N) AS [Ordinal],
SUBSTRING(@List, N, CHARINDEX(@Delimiter, @List + @Delimiter, N) - N) AS [Item]
@jbnv
jbnv / Object Code Query
Created June 2, 2015 00:51
SQL Server query to return the code for an object by name.
SELECT [Item]
FROM sys.sql_modules
CROSS APPLY (
SELECT ROW_NUMBER() OVER(ORDER BY N) AS [Ordinal],
SUBSTRING([definition], N, CHARINDEX(CHAR(13), [definition] + CHAR(13), N) - N) AS [Item]
FROM dbo.Numbers
WHERE N <= CONVERT(INT, LEN([definition]))
AND SUBSTRING(CHAR(13) + [definition], N, 1) = CHAR(13)
) t
WHERE OBJECT_NAME(object_id) = 'OBJECTNAME'
@jbnv
jbnv / Recency.js
Created June 2, 2015 00:55
Recency compare function (JavaScript)
// a, b: Date-time value (null if unknown or "never")
// altCompare: An alternative comparison function(a,b).
function recencyCompare(a,b) {
if (!a && !b) return altCompare(a,b);
if (!a) return 1; // 'b' has an error and 'a' doesn't
if (!b) return -1; // 'a' has an error and 'b' doesn't
if (a == b) { return altCompare(a,b); }
return a < b ? 1 : -1;
}
@jbnv
jbnv / ago.js
Created June 2, 2015 01:03
ago(date) function to return a brief "ago" string.
var second = 1e3;
var minute = 6e4;
var hour = 36e5;
var day = 864e5;
var week = 6048e5;
function ago(diff) {
var unit, num;
if (diff <= second) {
unit = 's';
@jbnv
jbnv / NameGenSSSpanish.sql
Created June 2, 2015 01:13
Name Generator (SQL Server; Spanish)
SELECT
ROW_NUMBER() OVER (ORDER BY surnames.[Surname],firstNames.[FirstName]) AS [Ordinal],
firstNames.[Gender],
firstNames.[FirstName],
surnames.[Surname]
FROM (
SELECT 'M' AS [Gender], [FirstName]
FROM (
SELECT 'Alberto' AS [FirstName]
UNION SELECT 'Angel' UNION SELECT 'Benito' UNION SELECT 'Carlos' UNION SELECT 'Domingo' UNION SELECT 'Fernando' UNION SELECT 'Federico' UNION SELECT 'Fidel'
@jbnv
jbnv / console.js
Created June 2, 2015 01:38
'console' custom binding for Knockout. Lets us dump a variable to the console from within our HTML.
composition.addBindingHandler('console', {
update: function (element, valueAccessor, allBindings) {
data = ko.toJS(valueAccessor() || allBindings());
console.log(data);
}
});
@jbnv
jbnv / CollectaAPI.vb
Created June 2, 2015 01:42
Collecta API Visual Basic .Net 3.5 Interface
Option Explicit On
Imports System
Imports System.Text
Imports System.Text.RegularExpressions
Imports System.Net
Imports System.Xml
Imports System.IO
Namespace Collecta
@jbnv
jbnv / camelize.js
Created June 22, 2015 15:05
camelize() function in JavaScript
camelize = function (str) {
return str.replace(/[\-_](\w)/g, function (match) {
return match.charAt(1).toUpperCase();
});
};