Skip to content

Instantly share code, notes, and snippets.

View zorab47's full-sized avatar
⌨️

Charles Maresh zorab47

⌨️
View GitHub Profile
@chrismo
chrismo / README.md
Last active October 19, 2016 20:32
Bundler 1.3 --binstubs vs. Rails 4

On a clean Rails 4 install with Bundler 1.3.0, using --binstubs causes competition between Rails and Bundler for the contents of bin/rails (and bin/rake).

Just running bundle will rewrite the Rails version of bin/rails to a version that doesn't work.

The fix is to use the new bundle binstubs <gemname> command.

(see rails/rails#8974)

@jcromartie
jcromartie / spark.rb
Created November 15, 2011 13:37
Sparklines in Ruby
#!/usr/bin/env ruby
# -*- coding: utf-8 -*-
# prints a sparkline in the terminal using the supplied list of numbers
# examples:
# spark.rb 10 20 30 100 90 80
# spark.rb 1 2 0.4 0.1 1.3 0.7
@ticks = %w[▁ ▂ ▃ ▄ ▅ ▆ ▇]
values = ARGV.map { |x| x.to_f }
@swrobel
swrobel / gemfile_changelog.rb
Created March 23, 2012 01:21
Get Changelogs for outdated gems in Gemfile
#!/usr/bin/env ruby
def changelog_for_gem(gem)
changelogs = `bundle exec gem contents #{gem}`.lines.grep(/history|changelog|news/i)
if changelogs.empty?
puts "No changelog found for gem #{gem}"
return nil
end
# Has your OS/FS/disk lost your data?
# cd to the directory containing your project repositories and run the command
# below. (It's long; make sure you get it all.) It finds all of your git repos
# and runs paranoid fscks in them to check their integrity.
(set -e && find . -type d -and -iname '.git' | while read p; do (cd "$(dirname "$p")" && (set -x && git fsck --full --strict)); done) && echo "OK"
# I have 81 git repos in my ~/proj directory and had no errors.
@dougc84
dougc84 / model.rb
Last active July 17, 2017 04:44
Ransack - Polymorphic Associations Search Ransacker
class MyModel < ActiveRecord::Base
belongs_to :owner, polymorphic: true
ransacker :owner_name, formatter: proc { |value|
# To use this, you have to know what all of the possible owner types can be.
# For this example, the #owner_type could be either Group or Advertiser.
# The fields we want to search on are:
# Group#name
# Advertiser#contact_name
#
@mudassir0909
mudassir0909 / selectable_placeholder.js
Last active September 30, 2017 03:18
Selectable Placeholder for selectize dropdown plugin
Selectize.define('selectable_placeholder', function( options ) {
var self = this;
options = $.extend({
placeholder: self.settings.placeholder,
html: function ( data ) {
return (
'<div class="selectize-dropdown-content placeholder-container">' +
'<div data-selectable class="option">' + data.placeholder + '</div>' +
'</div>'
@zorab47
zorab47 / offline_template.rb
Created November 22, 2011 16:18
Offline Template for Rails 2.3.x
# Public: Template to render views outside the context of a controller.
#
# Useful for rendering Rails 2.3.x views in rake tasks or background jobs when a
# controller is unavailable.
#
# Examples
#
# template = OfflineTemplate.new(:users)
# template.render("users/index", :layout => false, :locals => { :users => users })
#
@tfausak
tfausak / doctest.rb
Last active May 22, 2018 13:12
Test Ruby code in Markdown files.
#!/usr/bin/env ruby
pattern = /^```(.*)/
capturing = false
language = ''
lines = {}
File.open(ARGV.shift).each_line do |line|
match = pattern.match(line)
@livibetter
livibetter / termfps.sh
Last active January 31, 2020 02:10
testing terminal fps
#!/bin/bash
# Copyright (c) 2010, 2013 Yu-Jie Lin
#
# Permission is hereby granted, free of charge, to any person obtaining a copy of
# this software and associated documentation files (the "Software"), to deal in
# the Software without restriction, including without limitation the rights to
# use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
# of the Software, and to permit persons to whom the Software is furnished to do
# so, subject to the following conditions:
#
def transform_hash(original, options={}, &block)
original.inject({}){|result, (key,value)|
value = if (options[:deep] && Hash === value)
transform_hash(value, options, &block)
else
value
end
block.call(result,key,value)
result
}