Skip to content

Instantly share code, notes, and snippets.

View vidok's full-sized avatar

Dmitriy Burlutskiy vidok

  • Amsterdam, the Netherlands
View GitHub Profile
@vidok
vidok / Gemfile
Created October 6, 2022 12:06
ActiveSupport.HashWithIndifferentAccess benchmarks
# frozen_string_literal: true
ruby File.read(File.join(__dir__, '.ruby-version')).strip
source 'https://rubygems.org'
gem 'activesupport', '~>5.2.6'
gem "benchmark-memory"
class Hash
def collect!(&block)
ret = []
self.each {|key,val|
if val.kind_of? Array
val.collect!{|subval|
block.call subval
}
ret = val
end
class Hash
def deep_merge(other_hash, &block)
dup.deep_merge!(other_hash, &block)
end
def deep_merge!(other_hash, &block)
other_hash.each_pair do |k,v|
tv = self[k]
if tv.is_a?(Hash) && v.is_a?(Hash)
self[k] = tv.deep_merge(v, &block)
@vidok
vidok / cmetric.html
Created October 20, 2013 19:40
include cmetrics to wordpress
<!-- in footer.php -->
<?php if ($u->data->ID > 0): ?>
<script type="text/javascript">
var _cmq = _cmq || [];
_cmq.push(['identify', [<?=$u->data->ID?>, {email: "<?=$u->data->user_email;?>"}]]);
</script>
<?php endif; ?>
<script type="text/javascript">
var _cmq = _cmq || [];
var _cmk = _cmk || '0162cb4658a377810a1ad4979272a79e' //your token;
@vidok
vidok / eye.rb
Created October 16, 2013 12:26
eye puma configuration
Eye.load("./*.rb")
SERVER_WORK_DIR = File.expand_path(File.join(File.dirname(__FILE__), '../../'))
# Eye self-configuration section
Eye.config do
logger File.join(SERVER_WORK_DIR, 'log/eye.log')
end
# Adding application
Eye.application "statsio_client_alpha" do
var ValidateLocation = function()
{
this.execute = function(world, rooms, logger)
{
var checkAttributes = function(object, attributes) {
if (object == undefined )
return false;
for (var key in attributes) {
if (object.hasOwnProperty(attributes[key])) {
@vidok
vidok / intersection.rb
Last active December 21, 2015 21:49
Ruby hash intersection
hash = {"player" => {"food" =>90, "options" => {"location" => {"map_social_id" => 1}}, "exp" => 100}}
available_fileds = {
"player" => {"food" => 1, "exp" => 1}
}
class Hash
def intersection(another_hash)
keys_intersection = self.keys & another_hash.keys
merged = self.dup.update(another_hash)
@vidok
vidok / gist:6220371
Last active December 21, 2015 00:29
//Migration remove_clean_obst_large_tree
var _20130809164731 = function()
{
this.name = "remove_clean_obst_large_tree"; //имя указанное при создании миграции
this.version = 20130809164731; //время создания миграции
this.script_version = "dev_1376050014278"; //версия скриптинга
this.execute = function(world, rooms, context, config)
{
var removed_quest_name = 'clean_obst_large_tree';