Skip to content

Instantly share code, notes, and snippets.

sudo vi /etc/default/locale
LANGUAGE="ru_RU.UTF-8"
LC_ALL="ru_RU.UTF-8"
LANG="ru_RU.UTF-8"
LC_TYPE="ru_RU.UTF-8"
locale-gen ru_RU.UTF-8
dpkg-reconfigure locales
@creadone
creadone / gist:47b2323ba0326eca13c463cf234ec230
Created February 28, 2017 10:42 — forked from jordan-brough/gist:1926410
ruby count_by using group_by
# See http://jordan.broughs.net/archives/2012/07/enumerablecount_by-for-ruby
# Ruby >= 1.8.7 (incl 1.9.x)
module Enumerable
def count_by(&block)
Hash[group_by(&block).map { |key,vals| [key, vals.size] }]
end
end
@creadone
creadone / crystal_ext.cr
Last active August 19, 2019 17:42
Useful snippets for Crystal language
# Method alias
# ------------
macro alias_method(new_name, existing_method)
def {{new_name.id}}(*args)
{{existing_method.id}}(*args)
end
end
# Generate Union type from array of classes
@creadone
creadone / model.rb
Created January 13, 2020 18:09
Trace caller method
class Record < ApplicationRecord
TracePoint.trace(:call) do |tp|
pp [tp.method_id, tp.lineno, tp.path]
end
end
@creadone
creadone / page.md
Created January 24, 2020 20:59
Curl :: upload file with token auth and params
curl -v -H 'Content-Type: multipart/form-data' -H 'Accept: application/json' -H 'authorization: Token 1234' -F 'documents=@./upload.txt' -F "description=bla bla" http://0.0.0.0:8080/api/v1/upload
@creadone
creadone / index.js
Last active February 10, 2020 22:33
JavaScript: reference to own property
// Complex configuration object
var myObject = {
property1: { id: 1, name: 'value property1', handler: data => data.length },
get property2(){ return { ...this.property1, id: 2 } } // ref1
};
// > myObject.property2
// > {id: 2, name: "value property1", handler: f}
overview.props.$chart.getModel().getSeriesByName('uniqUsers')[0].getData().getVisual('color')
// Adaptive labels
// https://github.com/apache/incubator-echarts/issues/8841#issuecomment-516034572
echarts.registerLayout(ecModel => {
ecModel.eachSeries(seriesComponent => {
const data = seriesComponent.getData();
data.each(idx => {
const layout = data.getItemLayout(idx);
@creadone
creadone / index.html
Created April 12, 2020 23:41
Legend elements position
<div class='container'>
<div class='header'>1 — 25 февраля</div>
<div id='totalUsers' class='item'>
<div class='marker' style='background:#d2dbff'></div>
<div class='name'>Общая аудитория:</div>
<div class='value'>1,934</div>
</div>
<div id='uniqUsers' class='item'>
<div class='marker' style='background:#d8b2b9'></div>
<div class='desc'>Уникальные пользователи:</div>
@creadone
creadone / randomSumArray.js
Created April 19, 2020 05:45
N random numbers with constant sum
// https://stackoverflow.com/a/26976623/1597964
function randomSumArray(len, sum, d) {
var _sum = 0;
var arr = [];
var n, i;
if (!d && d !== 0) {
d = 100;
}
[
{ "category": "A", "value": 1 },
{ "category": "B", "value": 2 },
{ "category": "C", "value": 3 },
{ "category": "D", "value": 7 }
]