Skip to content

Instantly share code, notes, and snippets.

View realms-ai's full-sized avatar

Realms AI realms-ai

View GitHub Profile
@realms-ai
realms-ai / elastic-search.js
Created December 22, 2018 01:30
Elastic Search Query in Node.js
/**
* Making a Search Condition for Crawler Product in Elastic Search
*/
var search_condition = function(input){
return new Promise(function(resolve, reject) {
// Variables needed to execute functions and make condition
var conditions = {limit: input.limit || 10, offset: input.offset || 0 },
condition = [{term: {group_ids: input.group_id}}];
Promise.all([channel_group_conditions(input), pim_conditions(input), range_conditions(input), crawler_conditions(input)])
.then(function(condition){
@realms-ai
realms-ai / range_data_in_different_time_frames.rb
Created October 31, 2018 20:43
This store procedure gives data for graphs in different time frames for better analytics on IOT data
class GetRangeData < ActiveRecord::Migration[5.1]
def up
execute "
CREATE OR REPLACE FUNCTION public.GetRangeData(
thng_id INTEGER,
parameter VARCHAR,
duration INTEGER, -- 0 -> months, 1 -> weeks, 2 --> days, 3 --> hours
mnth INTEGER, -- 0 -> all_months, 1 -> Jan, 2 --> Feb, 3 --> Mar, ...., 12 --> Dec
yr INTEGER,
parameter_division INTEGER DEFAULT 1,
# Single Stack Multi Array
=begin
Question: Remove all consecutive characters from string whose count is even
Input
array = [
'azxxzyyyddddyzzz',
'xyzzyyyzx',
'cbbbaaaabbbccc'
]
How it works
@realms-ai
realms-ai / flatten_array.rb
Created August 7, 2018 06:08
Flatten array Citrusbyte
/#
How to Run the Program
1. Add list of arrays in the list below to test code
2. Execute the file from it's location
$ ruby array_flatten.rb
You will get your results as below
array: [1, 2, 3, [4, 5, 6, 7, [8, 9]]]
flatten_array: [1, 2, 3, 4, 5, 6, 7, 8, 9]