Skip to content

Instantly share code, notes, and snippets.

View qd3v's full-sized avatar
🏠
Working from home

Ivan Kulagin qd3v

🏠
Working from home
View GitHub Profile
@qd3v
qd3v / clion
Last active July 2, 2024 18:25
Jetbrains force us to use their Toolbox to get working CLI launchers in recent versions of standalone apps. I don't like that, and save these scripts. Drop these to /usr/local/bin
#!/usr/bin/env python3
# Copyright 2000-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
import os
import socket
import struct
import sys
import traceback
# See com.intellij.idea.SocketLock for the server side of this interface.
module SpecHelpers
# See more on this: https://github.com/vcr/vcr/issues/600
module VCRHooks
# @return [Proc] registered proc
def register_vcr_hook(type, *args, &block)
check_hook_type_valid!(type)
# Do not use #hooks hash directly, VCR wrap block into FilteredHook struct
VCR.configuration.send(type, *args, &block); block
@qd3v
qd3v / only_ar_rspec-rails_import.rb
Last active August 29, 2015 14:26
If you need only use_transactional_fixtures option
# Gemfile
gem 'rspec-rails', require: false
# spec_helper.rb
#
# IMPORT ONLY FIXTURE-RELATED CODE FROM rspec-rails
#
require 'rspec/rails/adapters'
# spec_helper.rb
require 'nokogiri'
require 'equivalent-xml/rspec_matchers'
RSpec.configure do |config|
# Should be used with be_equivalent_to provided by 'equivalent-xml' gem
# @see http://www.rubydoc.info/github/sparklemotion/nokogiri/Nokogiri/XML/Builder
# @see https://github.com/mbklein/equivalent-xml
def xml_document(&block)
Nokogiri::XML::Builder.new(&block).doc
require 'bundler/gem_tasks'
require 'active_record'
# Temporary switch to blank rake app, extract required tasks and import them to
# current rake task. Skip seed loader here, as we do not need it for tests.
# More info on AR tasks import: @see https://gist.github.com/drogus/6087979
def import_active_record_tasks(default_rake_app)
Rake.application = Rake::Application.new
Rake.application.rake_require('active_record/railties/databases')
@qd3v
qd3v / timecop.rb
Created December 24, 2014 14:58
Timecop explained
t = Time.local(2008, 9, 1, 10, 5, 0)
# Self-explained
Timecop.freeze(t) do
expect(Time.zone.now.sec).to eq 0
end
# The same as above
Timecop.freeze(new_time)
expect(Time.zone.now.sec).to eq 0