Skip to content

Instantly share code, notes, and snippets.

View CITguy's full-sized avatar

Ryan Johnson CITguy

View GitHub Profile
@CITguy
CITguy / gist:20ce9fed8582ff77d1d9
Last active August 29, 2015 14:01
Using Rails 4.1 Action Pack variants with Vendor MIME Type for simple API versioning
# config/routes.rb
Rails.application.routes.draw do
# use json if format not defined in url
scope(format: :json) do
get :hello, controller: :sandbox
end
end
# config/initializers/mime_types.rb
# Define a custom Vendor MIME type
@CITguy
CITguy / custom-task.js
Last active January 13, 2023 19:23
Basic pattern for creating a custom Transform stream for use with gulp tasks.
var gulp = require('gulp');
var myTransform = require('./myTransform');
gulp.task('foobar', function (){
return gulp.src("foobar.js")
.pipe(myTransform())
.pipe(gulp.dest('.'));
});
@CITguy
CITguy / tour.md
Last active February 18, 2016 23:05
Tour of Ruby Gems

Tour de Gems

Items in bold are those that I have the most experience.

Must Have Gems

  • bundler - It manages your project's gem versions, so you don't have to. If you aren't using it, see me after class ಠ_ಠ

Background Jobs

@CITguy
CITguy / component.js
Last active July 17, 2019 22:31
Deprecating AngularJS directives via console.warn()
app.directive('myOldDirective', function (myNewDirective) {
var warnMsg = 'DEPRECATION WARNING: myOldDirective has been marked as deprecated ' +
'and will be removed in a future release. ' +
'Please use myNewDirective as a replacement.';
console.warn(warnMsg); // jshint ignore:line
return myNewDirective[0];
});
@CITguy
CITguy / currencyToPennies.js
Last active October 9, 2015 15:13
String manipulation of currency to acquire penny amount
function currencyToPennies (currency) {
// ensure string
var strCurrency = currency.toString();
// ignore any character that's not part of a number
var wholeAmount = strCurrency.replace(/[^0-9.]/g, '');
// locate decimal
var decimalIndex = wholeAmount.indexOf('.');
var normalizedAmount;
@CITguy
CITguy / webplatform.md
Last active July 17, 2019 22:18
Web Platform
@CITguy
CITguy / hexo.js
Last active August 11, 2017 18:14
Using Browsersync + Hexo to run a local development server
#!/usr/bin/env node
'use strict';
const Hexo = require('hexo');
const YAML = require('js-yaml');
const fs = require('fs');
const cwd = process.cwd();
exports.hexo = new Hexo(cwd);
@CITguy
CITguy / fix-base-anchor-links-es5.js
Last active October 29, 2017 17:45
Use vanilla JavaScript to fix in-page anchors when using <base>
@CITguy
CITguy / medly-wordcloud.js
Created November 19, 2018 08:32
Rapid D3.js - Section 6 - Word Cloud example code
var fill = d3.scale.category20();
var layout = d3.layout.cloud()
.size([500, 500])
.words([
"Hello", "world", "normally", "you", "want", "more", "words",
"than", "this"].map(function(d) {
return {text: d, size: 10 + Math.random() * 90, test: "haha"};
}))
.padding(5)
.rotate(function() { return ~~(Math.random() * 2) * 90; })