Skip to content

Instantly share code, notes, and snippets.

View marat-chardymov's full-sized avatar

Marat Chardymov marat-chardymov

View GitHub Profile
@marat-chardymov
marat-chardymov / ring_buffer.rb
Created December 20, 2019 22:56
presumably thread safe ring buffer
module My
class RingBuffer
def initialize(size)
@size = size
@pointer = 0
@buffer = Array.new
@mutex = Mutex.new
end
def push(value)
@marat-chardymov
marat-chardymov / sinon_js_stub_any_instance_example.js
Last active February 18, 2019 03:45
Sinon.js : How to stub any instance of a class
const kinesisResponse = {
FailedRecordCount: 0,
Records: [{ SequenceNumber: 'test-sequence-number', ShardId: 'test-ShardId' }],
};
sinon.stub(KinesisClient.prototype, 'recordToKinesisStream').returns(Promise.resolve(kinesisResponse))
{
"data": [{
"type": "articles",
"id": "1",
"attributes": {
"title": "JSON API paints my bikeshed!"
},
"links": {
"self": "http://example.com/articles/1"
},
$ brew install chromedriver
#########################
Gemfile
group :test do
gem "chromedriver-helper"
gem 'selenium-webdriver'
end
@marat-chardymov
marat-chardymov / truncate_db.rake
Created February 27, 2017 17:33
Clear all postgres database with Rails
desc 'delete all data from db except migrations'
task :truncate_db => :environment do
conn = ActiveRecord::Base.connection
postgres = "SELECT tablename FROM pg_catalog.pg_tables WHERE schemaname='public'"
tables = conn.execute(postgres).map { |r| r['tablename'] }
tables.delete "schema_migrations"
tables.each { |t| conn.execute("TRUNCATE \"#{t}\" CASCADE") }
end

Look and Feel

  • quick theme change ctrl+back quote, enter presentation mode, change keymap quickly(might be useful for pair programming)

Navigation

  • alt home navigation bar(quicker than tree navigation isn't it?), alt+insert to create file on the spot or folder or rails generator
  • ctrl+shift+e recent files
  • run action (ctrl+shift+A)
  • find current file in project tree(Alt+f1)
  • !!! ctrl+click(ctrl+b go to declaration) global navigation by classes and methods, including 3rd party sources and yard docs/comments!!! (edited)
  • close block by clicking tiny minus, even if you're in the bottom of the block. Useful when you're dealing with big methods/json/xml
var blocksModule = (function () {
function pushSubNode(node, subNode) {
if (node.subNodes != null) {
node.subNodes.push(subNode);
} else {
node.subNodes = [subNode];
}
}