Skip to content

Instantly share code, notes, and snippets.

@dzhlobo
dzhlobo / arduino_loudness_detector.c
Created November 15, 2018 12:49
Arduino loudness detector
int frame_size = 300;
long int total = 0;
const int NUMBER_OF_LEDS = 6;
int leds[NUMBER_OF_LEDS] = {7, 6, 5, 4, 3, 2};
int thresholds[NUMBER_OF_LEDS] = {5, 10, 15, 20, 25, 30};
void setup() {
Serial.begin(9600);
class PostsController < ApplicationController
def index
render cell: :index, model: posts
end
def show
post_view_registrar.commit_view
show_post_page
end
@dzhlobo
dzhlobo / sieve.rb
Created June 23, 2015 11:58
Prime numbers
class PrimeNumbers
include Enumerable
def self.prime_numbers_below(edge)
new(max_number: edge)
end
def initialize(max_number:)
@max_number = max_number
end
@dzhlobo
dzhlobo / gist:14909fb21677ced48942
Last active August 29, 2015 14:15
SQL float comparison
MariaDB > SELECT id, summary_rating FROM companies ORDER BY summary_rating DESC;
+-------+----------------+
| id | summary_rating |
+-------+----------------+
| 75748 | 4.8 |
| 61769 | 4.76842 |
| 12475 | 4.59091 |
| 29849 | 4.54 |
+-------+----------------+
# Concern:
module Searchable
extend ActiveSupport::Concern
included do
include Elasticsearch::Model
scope :searchable, -> { where(searchable: true) }
end
module ClassMethods
@dzhlobo
dzhlobo / test
Created July 1, 2013 10:49
Tune analyzing process
$ cat test_index.json
{
"settings": {
"number_of_shards": 1,
"analysis": {
"analyzer": {
"titleAnalyzer": {
"tokenizer": "titleTokenizer",
"filter": ["lowercase"]
}
module Tire
module Disable
module ClassMethods
def mock_es_response_doc
@mock_es_response_doc ||=
'{"took": 1,"timed_out": false,"_shards": {"total": 5,"successful": 5,"failed": 0},"hits": {"total": 0,"max_score": null,"hits": []}}'
end
def enable! &blk
old_enabled = @tire_enabled || false
@dzhlobo
dzhlobo / .gitconfig
Created October 31, 2012 17:15
My .gitconfig
[user]
name = Dmitry Zhlobo
email = dima.zhlobo@gmail.com
[alias]
co = checkout
ci = commit
st = status -s
br = branch
hist = log --pretty=format:\"%h %ad | %s%d [%an]\" --graph --date=short
lg = !git --no-pager log --graph --pretty=tformat:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr)%Creset [%an]' --abbrev-commit --date=short -20
@dzhlobo
dzhlobo / gem.rb
Created May 1, 2012 20:40 — forked from wkj/gem.rb
Build and install a gem for testing with Cucumber and Aruba
# Copyright 2011 Solano Labs All Rights Reserved
require 'aruba/api'
class CukeGem
@setup_done = false
class << self
include Aruba::Api
@dzhlobo
dzhlobo / analyzer.rb
Created January 4, 2012 07:16
Simple text analyzer
# analyzer.rb -- Text Analyzer
lines = File.readlines(ARGV.first)
line_count = lines.size
text = lines.join
# Count the characters
total_characters = text.length
total_characters_nospaces = text.gsub(/\s+/, '').length