Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@biganth
biganth / rails-search.html
Last active March 23, 2016 15:20
Rails search with Twitter Typeahead
<form id="search_form" action="/listings/search" method="get">
<%= hidden_field_tag :search_item_id %>
<%= hidden_field_tag :search_item_type %>
<fieldset>
<span class="search">
<% q = params[:term].to_s.empty? ? "Instant search result as you type" : params[:term] %>
<script>var start_search = true</script>
<input type="text" class="input" id="search_field" name="q" value="<%=q%>" onclick="if(this.value=='Instant search results as you type'){this.value=''};start_search=true;$('search_results').hide()" autocomplete="off" />
&nbsp;<%= indicator("search_ind") %>
</span>
@biganth
biganth / Angular-Web-API2.js
Last active April 1, 2016 12:59
Angular hitting Web API 2
var app = angular.module('CarFinderApp', []);
app.controller('DisplayController', ['$scope', '$http', function ($scope, $http) {
$scope.selected = {
year: '',
make: '',
model: '',
trim: ''
};
}
@biganth
biganth / web-api-external-login.js
Last active March 23, 2016 15:21
Web API2 external login
function Login() {
jQuery.support.cors = true;
$.ajax({
type: 'GET',
url: 'api/Account/ExternalLogins?returnUrl=%2F&generateState=true',
dataType: 'JSON',
success: function (data) {
var url = (data[0].Url);
window.open(url, '_self', false);
}
@biganth
biganth / slugIt.js
Last active April 1, 2016 12:57
Create urls based on blog post title
//Turns "My first blog post" into my-first-blog-post
function slugIt() {
let title = document.getElementById("title");
let slug = document.getElementById("slug");
slug.value = title.value.replace(/ /g, "-").toLowerCase();
}
@biganth
biganth / StreamToExcel.cs
Created March 23, 2016 15:13
Export a stream of data to CSV
FileStream fileStream = new FileStream("C:\\Temp\\EncompassExtract.csv", FileMode.Create);
var streamWriter = new StreamWriter(fileStream);
streamWriter.AutoFlush = true;
StringBuilder line = new StringBuilder();
line.AppendFormat("User" + "," + "UserId" + "," + "Account Enabled");
line.Append(Environment.NewLine);
foreach (User user in users)
{
line.AppendFormat(user.FullName + "," + user.Id + "," + user.Enabled);
line.Append(Environment.NewLine);