Skip to content

Instantly share code, notes, and snippets.

View smockle's full-sized avatar

Clay Miller smockle

View GitHub Profile
@andrewbranch
andrewbranch / defer-with-promise.js
Created December 19, 2014 03:20
Explore the effect of Promises on JS speed and order of execution
var trash = [];
function computationallyIntensiveStuff() {
trash.push(Math.pow(Math.pow(Math.cos(Math.sin(Math.random())), Math.random()), Math.random() * 100000));
trash.filter(function (a) { return a > Math.random(); });
}
new Promise(function (resolve, reject) {
for (var i = 0; i < 1000; i++) {
@andrewbranch
andrewbranch / sort.js
Last active September 1, 2015 01:16
Variadic sort
function getTestPeople() {
return [{
name: "Kylie",
age: 18
}, {
name: "Andrew",
age: 23
}, {
name: "Andrew",
age: 18
NameVirtualHost 127.0.0.1:80
<VirtualHost 127.0.0.1:80>
ServerName pow
ServerAlias *.dev
ServerAlias *.xip.io
ProxyPass / http://localhost:20559/
ProxyPassReverse / http://localhost:20559/
ProxyPreserveHost On
@TheTfactor
TheTfactor / PDF Display Notes.cs
Created April 17, 2013 14:17
PDF display options. Prevents autodownloading.
HttpContext.Current.Response.BufferOutput = true;
HttpContext.Current.Response.ClearContent();
HttpContext.Current.Response.ClearHeaders();
HttpContext.Current.Response.AddHeader("Cache-control", "no-store");
HttpContext.Current.Response.AddHeader("Content-Disposition", "inline; filename=\"" + fileName + "\"");
HttpContext.Current.Response.ContentType = dr["MimeType"].ToString();
HttpContext.Current.Response.AddHeader("Content-Length", fileblob.Length.ToString());
HttpContext.Current.Response.BinaryWrite(fileblob);
HttpContext.Current.Response.Flush();
HttpContext.Current.ApplicationInstance.CompleteRequest();
@smockle
smockle / Fields.rb
Last active December 17, 2015 11:29
Fields lists Rails database column types.
# DATABASE TYPES
# eg. field_name:field_type
:string, :text, :integer, :float, :decimal, :datetime, :timestamp, :time, :date, :binary, :boolean, :references
// jonathantneal's polyfill for matchesSelector
if (this.Element) function(ElementPrototype) {
ElementPrototype.matches = ElementPrototype.matchesSelector =
ElementPrototype.matchesSelector ||
ElementPrototype.webkitMatchesSelector ||
ElementPrototype.mozMatchesSelector ||
ElementPrototype.msMatchesSelector ||
ElementPrototype.oMatchesSelector ||
function (selector) {
var nodes = (this.parentNode || this.document).querySelectorAll(selector), i = -1;
@andrewbranch
andrewbranch / getAuburnBuildings.js
Last active December 21, 2015 04:59
Gets an array of Auburn building names from the web API. Works from auburn.edu domain and subdomains.
var auburnBuildingNames;
window.getAuburnBuildingNames = function(callback) {
if (auburnBuildingNames) {
callback(auburnBuildingNames);
} else {
var buildings;
$.getJSON("https://cws.auburn.edu/map/api/3.0/building", function(data) {
buildings = $.map(data, function(building, i) {
return building.name;
@andrewbranch
andrewbranch / BundleConfig.cs
Last active December 21, 2015 11:38
Bundling with BundleTransformer in ASP.NET MVC. Less files need to have their Build Action set to "Content" in their file properties in order to publish successfully.
using System.Web;
using System.Web.Optimization;
using BundleTransformer.Core.Transformers;
namespace Project {
public class BundleConfig {
public static void RegisterBundles(BundleCollection bundles) {
@andrewbranch
andrewbranch / ExampleView.aspx
Created September 10, 2013 16:44
HtmlHelper to generate JavaScript object from C# object
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
<%= Html.WriteToJavaScript(Model, "window.model") %>
</asp:Content>
@stormsilver
stormsilver / unbundled_require.rb
Created October 15, 2012 19:59 — forked from zaius/unbundled_require.rb
Allow requiring of global gems from outside of the Gemfile
# Include this in your .irbrc
def unbundled_require(gem, options = {})
if defined?(::Bundler)
spec_path = Dir.glob("#{Gem.dir}/specifications/#{gem}-*.gemspec").last
if spec_path.nil?
warn "Couldn't find #{gem}"
return
end
spec = Gem::Specification.load spec_path