Skip to content

Instantly share code, notes, and snippets.

View jah2488's full-sized avatar
:fishsticks:

Justin Herrick jah2488

:fishsticks:
View GitHub Profile
def compress_before_seeing_avdis_answer(str)
result = str.chars.chunk(&:to_s).map { |char, chars| "#{char}#{chars.length}" }.join
return str if result.length > str.length
result
end
def compress(str)
[
str
@jah2488
jah2488 / application_controller.rb
Created October 21, 2014 22:14
It works! Kinda. This is some terrifying code, but it will give you method suggestions on the error you received in your rails code using the rails inflector.
class ApplicationController < ActionController::Base
# Prevent CSRF attacks by raising an exception.
# For APIs, you may want to use :null_session instead.
protect_from_forgery with: :exception
rescue_from NoMethodError, with: :try_to_inflect
def try_to_inflect(err)
@jah2488
jah2488 / debug_css.js
Last active January 3, 2023 21:53
Fun little one liner to do some debugging css.
function debugAll() {
[].forEach.call($$('*'), function(a) {
function cr() { return 0|(Math.random() * 255); };
a.style.outline = '2px solid rgba(' + [cr(), cr(), cr()].join(',') + ', 0.44)';
});
}
var gulp = require('gulp');
var sass = require('gulp-sass');
var connect = require('gulp-connect');
var jshint = require('gulp-jshint');
var stylish = require('jshint-stylish');
gulp.task('lint', function () {
return gulp.src('./app/scripts/*.js')
.pipe(jshint())
.pipe(jshint.reporter('jshint-stylish'));
@jah2488
jah2488 / gulpfile.js
Created September 29, 2014 17:49
Time to get Sassy
'use strict'
var gulp = require('gulp');
var sass = require('gulp-sass');
var watch = require('gulp-watch');
gulp.task('default', function () {
gulp.src('app/styles/*.scss')
.pipe(watch('app/styles/*.scss', function(files) {
return files
@jah2488
jah2488 / core_ext.rb
Created September 18, 2014 02:12
Some Kernel methods to aid in debugging / code readability from Michael Feather's blog post https://michaelfeathers.silvrback.com/literate-chains-for-functional-programming
module Kernel
def c(*)
self
end
def show(&block)
def c(*args) puts args, self; end
block.call
def c(*) self; end
end
@jah2488
jah2488 / a_view.html.erb
Last active August 29, 2015 14:06
Kinda like this.
<%= render :layout => 'shared/content_container' do %>
<% render :layout => 'shared/record_grid', :locals => { records: @grid_things } do |thing| %>
<%= render partial: "grid_thing", locals: { grid_thing: thing} %>
<% end %>
<% end %>
@jah2488
jah2488 / main.clj
Last active August 29, 2015 14:06 — forked from tylerjohnst/one.clj
(ns problem1.core)
(defn- real-numbers-below [x] (range 1 x))
(defn- multiple-of [x num] (zero? (mod x num))
(defn- multiple-of-three [x] (multiple-of x 3))
(defn- multiple-of-five [x] (multiple-of x 5))
(defn multiple-of-three-or-five [x]
(or (multiple-of-three x)
(multiple-of-five x)))
@jah2488
jah2488 / HfgGo.markdown
Created August 25, 2014 16:50
A Pen by Justin Herrick.
@jah2488
jah2488 / wat.rb
Last active August 29, 2015 14:04
View the revisions.
def timer_start(picker)
respond_with(time_entry_from_picker(picker))
end
private def time_entry_from_picker(picker)
return picker.time_entires.create unless picker.time_entries.last.running? || picker.time_entries.present?
picker.time_entries.last
end