Skip to content

Instantly share code, notes, and snippets.

@gor-sg
gor-sg / gist:689b535d6f060cfa466f2b2903af3609
Created April 27, 2020 12:19
create inventory numbers
numbers = `curl https://gist.githubusercontent.com/gor-sg/6e8296dcc76200fc59ea81b97bb0c2f2/raw/7d8d83baef7a29a4ea86e5bc70aa7c4535758c9f/gistfile1.txt`.split
numbers.each {|n| Inventory.create(survey_number: n, inventory_snapshot_id: 1, created_at: Date.yesterday)}
# frozen_string_literal: true
module CustomFlatten
def self.included(base)
base.class_eval do
alias_method :old_flatten, :flatten
end
end
def flatten
@gor-sg
gor-sg / gist:e6e9b7b21c03f20910c7
Created October 29, 2015 10:45
christmas tree
n = 22; m = 2; (1..n).select(&:odd?).each{ |i| p (" " * ((n - 1)/2 - i/2) + "x" * i) }; m.times{ |x| p (' ' * ((n - 1)/2) + 'x') }
" x"
" xxx"
" xxxxx"
" xxxxxxx"
" xxxxxxxxx"
" xxxxxxxxxxx"
" xxxxxxxxxxxxx"
" xxxxxxxxxxxxxxx"
" xxxxxxxxxxxxxxxxx"
var page = require('webpage').create(),
address;
if (phantom.args.length != 1) {
console.log('Usage: preview.js URL filename');
phantom.exit();
} else {
address = phantom.args[0];
//output = phantom.args[1];
var page = require('webpage').create();
page.settings.userAgent = 'WebKit/534.46 Mobile/9A405 Safari/7534.48.3';
page.settings.viewportSize = { width: 400, height: 600 };
page.open('http://habrahabr.ru', function (status) {
if (status !== 'success') {
console.log('Unable to load BBC!');
phantom.exit();
} else {
window.setTimeout(function () {
page.clipRect = { left: 0, top: 0, width: 400, height: 600 };
Regexps for tests
(?<!#)\s([^\s]+)\.should_not
expect(\1).not_to
(?<!#)\s([^\s]+)\.should
expect(\1).to
( +)(.+)\.should
\1expect(\2).to
#!/bin/sh
PROCFILE="mysql: mysqld
elasticsearch: elasticsearch --config=/usr/local/opt/elasticsearch/config/elasticsearch.yml
redis: redis-server /usr/local/etc/redis.conf
sidekiq: bundle exec sidekiq -C './config/sidekiq.yml'
app: bundle exec rails s"
ps aux | grep '[m]ysql\|[e]lasticsearch\|[r]edis\|[r]ails\|[s]idekiq\|[f]oreman' | awk '{print $2}' | xargs kill SIGTERM
@gor-sg
gor-sg / 0_reuse_code.js
Created July 29, 2014 08:14
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@gor-sg
gor-sg / gist:58190bf4fcea701732bc
Created July 25, 2014 07:40
Clean all sidekiq queues
require 'sidekiq/api'
Sidekiq::Stats.new.queues.keys.map { |name| ::Sidekiq::Queue.new(name) }.map(&:clear)
@gor-sg
gor-sg / gist:8351120
Created January 10, 2014 12:27
Setup ubuntu 13.10
sudo adduser pi
sudo adduser pi sudo
sudo apt-get install software-properties-common python g++ make
sudo add-apt-repository ppa:chris-lea/node.js
sudo apt-get update
sudo apt-get install nodejs