Skip to content

Instantly share code, notes, and snippets.

View Eric-Guo's full-sized avatar

Eric Guo Eric-Guo

View GitHub Profile
@thirdwing
thirdwing / lsos.R
Last active December 30, 2015 13:39
# improved list of objects by Dirk
.ls.objects <- function (pos = 1, pattern, order.by,
decreasing=FALSE, head=FALSE, n=5) {
napply <- function(names, fn) sapply(names, function(x)
fn(get(x, pos = pos)))
names <- ls(pos = pos, pattern = pattern)
obj.class <- napply(names, function(x) as.character(class(x))[1])
obj.mode <- napply(names, mode)
obj.type <- ifelse(is.na(obj.class), obj.mode, obj.class)
obj.size <- napply(names, object.size)
@rjocoleman
rjocoleman / gist:7853529
Last active December 30, 2015 16:19
Using knife-solo with Chef 11.8.2 on Windows. Making use of Opscode's embedded MinGW (aka RubyInstaller DevKit).

Current as of Chef 11.8.2
Opscode bundle RubyInstaller DevKit with Chef as their embedded environment. RubyInstaller DevKit is a basically a packaging of MinGW/MSYS. It's intended for Chef internal use only and does not include everything we need (but it's close).

Knife-Solo dependencies:

  • Chef
  • A SSH server (communication)
  • rsync (to transfer cookbooks etc)

Please note this is highly dependent on what Opscode bundle with Chef. These won't be supported by Opscode and could completely break your chef-client installation. Updates to Chef will likely remove rsync and it will need to be reinstalled. Opscode might stop using DevKit entirely without warning and break this whole technique.

@gythialy
gythialy / LicenseEngine.cs
Last active June 13, 2022 02:50
remove license validation of MarkdownPad 2 by Mono Cecil
public bool VerifyLicense(string licenseKey, string email)
{
if (string.IsNullOrEmpty(licenseKey) || string.IsNullOrEmpty(email))
{
return false;
}
try
{
this.License = this.Decrypt(licenseKey);
this.LicenseProcessed = true;
source :rubygems
# We are not loading Active Record, nor Active Resources etc.
# We can do this in any app by simply replacing the rails gem
# by the parts we want to use.
gem "actionpack", "~> 4.0"
gem "railties", "~> 4.0"
gem "tzinfo"
# Let's use thin
@andyjbas
andyjbas / gist:9962218
Last active June 23, 2020 13:33
Disable CSS Animations in Poltergeist & Phantomjs. Phantomjs does not like to wait for animations, and you can run in to nasty test flickers because of it. This pattern will disable animations in test env, and not touch any app code.
# env.rb or spec_helper.rb

Capybara.register_driver :poltergeist do |app|
  opts = {
    extensions: ["#{Rails.root}/features/support/phantomjs/disable_animations.js"] # or wherever
  }

  Capybara::Poltergeist::Driver.new(app, opts)
end
@leikind
leikind / render.rb
Created April 20, 2014 11:49
rails render and content type
render :inline => '<html><b>123</b></html>' #=> Content-Type: text/html; charset=utf-8
# Good
render json: {1 => 2}.to_json #=> Content-Type: application/json; charset=utf-8
# this was correct
render xml: '<xml><foo>123</foo></xml>' #=> Content-Type: application/xml; charset=utf-8
@buntine
buntine / deploy.rb
Created July 14, 2014 01:36
Rails 4, Capistrano 3.2.1+ local precompilation using rsync
# Clear existing task so we can replace it rather than "add" to it.
Rake::Task["deploy:compile_assets"].clear
desc "Precompile assets locally and then rsync to web servers"
task :compile_assets do
on roles(:web) do
rsync_host = host.to_s
run_locally do
with rails_env: :production do ## Set your env accordingly.
@Jesus
Jesus / deploy.rb
Last active June 2, 2016 23:31 — forked from buntine/deploy.rb
# Clear existing task so we can replace it rather than "add" to it.
Rake::Task["deploy:compile_assets"].clear
desc "Precompile assets locally and then rsync to web servers"
task :compile_assets do
# compile assets locally
run_locally do
with rails_env: fetch(:stage) do
execute :bundle, "exec rake assets:precompile"
end
@mlr
mlr / rspec_rails_cheetsheet.rb
Last active October 26, 2023 14:32 — forked from them0nk/rspec_rails_cheetsheet.rb
Rspec Rails cheatsheet with expect syntax (including capybara matchers)
# Model
expect(@user).to have(1).error_on(:username) # checks whether there is an error in username
expect(@user.errors[:username]).to include("can't be blank") # check for the error message
# Rendering
expect(response).to render_template(:index)
# Redirecting
@shouya
shouya / change.rb
Last active September 27, 2015 02:55
presentation @ gzruby, oct 2014
class Operation < Struct.new(:name, :args, :block)
class << self
attr_accessor :opposite_operations
end
def self.define_opposite_operations(name, name_of_opposite)
@opposite_operations ||= {}
@opposite_operations[name] = name_of_opposite
@opposite_operations[name_of_opposite] = name
end