how to delete character in ruby command line - ruby

I have a .txt file that contain my schedule of playlist for my tv channel. In the file there are many characters as 'logo_0 2' in. I run a ruby command to process the playlist (.txt file). How i want to delete these all 'logo_0 2' in the ruby ? Attached herewith is the .txt file and the rb file to execute the process. I need to eliminate the 'logo_0 2' in .txt file.
ITEM
preset_date 04/08/16
preset_time 22:09:00:00
title Awani (Comedy) Obviously Harith Iskander Sat Ep11 : Logo Inti College + Air Asia + Radio (E) Aug06 Sat 9.30pm
clip HUZKN01HM01AS
in_src 928500
out_src 929250
mode 1
no_vision_trans 1
no_audio_trans 1
type 1
logo_0 2
user_data 05_I_148671633
aspect_ratio 2
channel_id 2
use_subtitle 0
end
ITEM
preset_date 04/08/16
preset_time 22:09:30:00
title RiaHD (Series) Lelaki Macam Dia : Generic (Bm) Isnin - Khamis # 2200
clip HUJST01HM01DV
in_src 1018125
out_src 1018875
mode 1
no_vision_trans 1
no_audio_trans 1
type 1
logo_0 2
user_data 05_I_148669553
aspect_ratio 2
channel_id 2
use_subtitle 0
end
ITEM
preset_date 04/08/16
preset_time 22:10:00:00
title Citra Mustika (Movie Compact) August Highlights (Bm)
clip HUXAP01HM01CM
in_src 962500
out_src 963250
mode 1
no_vision_trans 1
no_audio_trans 1
type 1
logo_0 2
user_data 05_I_148671344
aspect_ratio 2
channel_id 2
use_subtitle 0
end
ITEM
preset_date 04/08/16
preset_time 22:10:30:00
title Awani (News) Awani 7.45 (Bm) Setiap Hari # 1945
clip HULHP01HM01AE
in_src 909000
out_src 909750
mode 1
no_vision_trans 1
no_audio_trans 1
type 1
logo_0 2
user_data 05_I_148671634
aspect_ratio 2
channel_id 2
use_subtitle 0
end
ITEM
preset_date 04/08/16
preset_time 22:11:00:00
title Episode Number 880
clip TAPE_REPLACEMENT
in_src 0
out_src 12000
mode 1
no_vision_trans 1
no_audio_trans 1
type 1
logo_0 1
notes Isu utama harian dan mingguan dikupas dengan mendalam oleh ahli panel.
user_data 05_P_174282654
logo_data_0 0
channel_id 2
end
ITEM
preset_date 04/08/16
preset_time 22:19:00:00
title Awani (News) Buletin Awani Noon (Bm) Setiap Hari # 1200
clip HUUIL01HM01AI
in_src 915000
out_src 915750
mode 1
no_vision_trans 1
no_audio_trans 1
type 1
logo_0 2
user_data 05_I_148671635
aspect_ratio 2
channel_id 2
use_subtitle 0
end
ITEM
preset_date 04/08/16
preset_time 22:19:30:00
title Sports Rio Olympics 2016 - Opening Ceremony (BM) Live Aug6 6.55am
clip HUUUY01HM01AB
in_src 904000
out_src 904750
mode 1
no_vision_trans 1
no_audio_trans 1
type 1
logo_0 2
user_data 05_I_148668511
aspect_ratio 2
channel_id 2
use_subtitle 0
end
ITEM
preset_date 04/08/16
preset_time 22:20:00:00
title Awani (Biz News) Bisnes Awani Plus (Bm) Sabtu # 1830
clip HPVAP01HM01DU
in_src 1050000
out_src 1050750
mode 1
no_vision_trans 1
no_audio_trans 1
type 1
logo_0 2
user_data 05_I_148671638
aspect_ratio 2
channel_id 2
use_subtitle 0
end

It would be good if you share your ruby code and we can show you how to update it.
filename = 'item.txt'
contents=File.read(filename)
contents.gsub!("logo_0 2\n", '')
File.open(filename, "w") { |f| f << contents }
In case you only want to replace characters contents.gsub!("logo_0 2", '') use this statement in place of contents.gsub!("logo_0 2\n", '')

Related

Laravel consoletv/charts v 6.0 - Get count per day and per Item name

How do i query to make total count per day based on a name or an id?
id
name
1
Facebook
2
Twitter
3
Reddit
id
page_id
social_id
visited_at
1
1
1
2021-03-27
2
1
1
2021-03-27
3
1
2
2021-03-27
4
1
2
2021-03-27
5
1
3
2021-03-27
6
1
3
2021-03-27
7
1
1
2021-03-28
8
1
1
2021-03-28
9
1
2
2021-03-28
10
1
2
2021-03-28
11
1
3
2021-03-28
12
1
3
2021-03-28
With the following query i get count of click on all social anchors per day, but i want to show in the chart also which social anchor has been clicked on that day.
$social_stats= Social::join('social_statistics', 'social_statistics.social_id','socials.id')
->select( array(
'social_statistics.visited_at as visited_at',
DB::raw('count(*) as count'),
)
)
->orderBy('visited_at')
->groupBy('visited_at')
->pluck('count','visited_at')
->all();
Need to render a Chart that shows by day the count of click on different social.
$social_bar_chart = new SocialBarChart;
$visited_at = collect(array_keys($this->social_bar));
$social_bar_labels = $visited_at->map(function ($date) {
return Carbon::parse($date)->format('d/m');
})->toArray();
$social_bar_chart->labels($social_bar_labels)
->dataset('Social Count', 'bar', array_values($this->social_bar))
->options([
'tooltip' =>['show' => true],
'backgroundColor' => '#54a0ff',
]);

Send postscript file pages to different trays

I am trying to print a postscript file where the first page has to use one tray and the second page has to use a second one.
I have tried this using setDevice but it does not work. The printer either sends all pages to one tray or to another but does not switch between pages.
I tried with the following command
<</ManualFeed false /MediaPosition 0>> setpagedevice
I tried placing it before the %%BeginPageSetup and within the %%BeginPageSetup but it does not make a difference. I use ghostscript command to send it to the printer.
<</ManualFeed false /MediaPosition 0>> setpagedevice
%%Page: 1 1
%%BeginPageSetup
GS_pswrite_2_0_1001 begin
595 842 /a4 setpagesize
/pagesave save store 197 dict begin
0.1 0.1 scale
%%EndPageSetup
gsave mark
...
cleartomark end end pagesave restore
showpage
%%PageTrailer
<</ManualFeed false /MediaPosition 1>> setpagedevice
%%Page: 2 2
%%BeginPageSetup
GS_pswrite_2_0_1001 begin
595 842 /a4 setpagesize
/pagesave save store 197 dict begin
0.1 0.1 scale
%%EndPageSetup
gsave mark
...
cleartomark end end pagesave restore
showpage
%%PageTrailer
Here is the prolog
%%BeginProlog
% This copyright applies to everything between here and the %%EndProlog:
% Copyright (C) 2008 Artifex Software, Inc. All rights reserved.
%%BeginResource: procset GS_pswrite_2_0_1001 1.001 0
/GS_pswrite_2_0_1001 80 dict dup begin
/PageSize 2 array def/setpagesize{ PageSize aload pop 3 index eq exch
4 index eq and{ pop pop pop}{ PageSize dup 1
5 -1 roll put 0 4 -1 roll put dup null eq {false} {dup where} ifelse{ exch get exec}
{ pop/setpagedevice where
{ pop 1 dict dup /PageSize PageSize put setpagedevice}
{ /setpage where{ pop PageSize aload pop pageparams 3 {exch pop} repeat
setpage}if}ifelse}ifelse}ifelse} bind def
/!{bind def}bind def/#{load def}!/N/counttomark #
/rG{3{3 -1 roll 255 div}repeat setrgbcolor}!/G{255 div setgray}!/K{0 G}!
/r6{dup 3 -1 roll rG}!/r5{dup 3 1 roll rG}!/r3{dup rG}!
/w/setlinewidth #/J/setlinecap #
/j/setlinejoin #/M/setmiterlimit #/d/setdash #/i/setflat #
/m/moveto #/l/lineto #/c/rcurveto #
/p{N 2 idiv{N -2 roll rlineto}repeat}!
/P{N 0 gt{N -2 roll moveto p}if}!
/h{p closepath}!/H{P closepath}!
/lx{0 rlineto}!/ly{0 exch rlineto}!/v{0 0 6 2 roll c}!/y{2 copy c}!
/re{4 -2 roll m exch dup lx exch ly neg lx h}!
/^{3 index neg 3 index neg}!
/f{P fill}!/f*{P eofill}!/s{H stroke}!/S{P stroke}!
/q/gsave #/Q/grestore #/rf{re fill}!
/Y{P clip newpath}!/Y*{P eoclip newpath}!/rY{re Y}!
/|={pop exch 4 1 roll 1 array astore cvx 3 array astore cvx exch 1 index def exec}!
/|{exch string readstring |=}!
/+{dup type/nametype eq{2 index 7 add -3 bitshift 2 index mul}if}!
/#/currentfile #/${+ # |}!
/B{{2 copy string{readstring pop}aload pop 4 array astore cvx
3 1 roll}repeat pop pop true}!
/Ix{[1 0 0 1 11 -2 roll exch neg exch neg]exch}!
/,{true exch Ix imagemask}!/If{false exch Ix imagemask}!/I{exch Ix image}!
/Ic{exch Ix false 3 colorimage}!
/F{/Columns counttomark 3 add -2 roll/Rows exch/K -1/BlackIs1 true>>
/CCITTFaxDecode filter}!/FX{<</EndOfBlock false F}!
/X{/ASCII85Decode filter}!/#X{# X}!/&2{2 index 2 index}!
/#F{# &2<<F}!/#C{#X &2 FX}!
/$X{+ #X |}!/&4{4 index 4 index}!/$F{+ # &4<<F |}!/$C{+ #X &4 FX |}!
/IC{3 1 roll 10 dict begin 1{/ImageType/Interpolate/Decode/DataSource
/ImageMatrix/BitsPerComponent/Height/Width}{exch def}forall
currentdict end image}!
/~{# read {pop} if}!
end def
%%EndResource
/pagesave null def
%%EndProlog
Thanks for you help,
Pat
This isn't really a Ghostscript question.
The selection of tray position is device-dependent, you need to find out what your particular PostScript printer needs. If that fragment of PostScript is correct, then all I can suggest is that you try putting the setpagedevice after the setpagesize. I can't recall offhand exactly what that routine does, and you haven't included the entire prolog, but it certainly will involve a call to setpagedevice.
The obvious way to test this, of course, is to send a simple 'do nothing' PostScript test program with the tray selection commands to the printer:
%!
<</ManualFeed false /MediaPosition 0>> setpagedevice
showpage
<</ManualFeed false /MediaPosition 1>> setpagedevice
showpage
That should eject a blank page from each tray. If that doesn't work, then you need some other magic for your printer.
I note that the PostScript is fairly obviously the output from Ghostscript's ps2write device. You can have that device inject the PostScript for you by using the PSPageOptions switch. Of course, the PostScript still has to be correct for the device.

How to sort kibana indices by descending size?

I tried this first: GET _cat/indices which gave me all of my indices.
I added GET _cat/indices?v to get the column names so I would be able to sort by column name like this GET _cat/indices?v&s=store.size
Now, I just want to swap the sort order.
ElasticSearch guide had no information regarding this.
You can use the suffix :desc like this to get there:
http://localhost:9200/_cat/indices/?s=store.size:desc
health status index uuid pri rep docs.count docs.deleted store.size pri.store.size
yellow open tmdb DVLEul7bT4yGyiq34h4nCQ 1 1 27760 0 119.8mb 119.8mb
green open .kibana_2 6WJ3UFpOSj2O8zi-iLuw6w 1 0 10 0 35.3kb 35.3kb
green open .kibana_task_manager_1 WSwYXmMOSpyQOQ8ZIRniwg 1 0 2 0 31.6kb 31.6kb
green open .tasks _SsI5VWNSwO5Yfps3K12Qg 1 0 1 0 6.3kb 6.3kb
green open .kibana_1 MukHGTHfTkKS1HcYodfNqA 1 0 1 0 4kb 4kb
yellow open my_index 7FgIWDJOSQesKbJI-HKRoA 1 1 1 0 3.8kb 3.8kb
green open .ltrstore -Xh6WnJYSsWIoPGP8fhgGw 1 0 0 0 283b 283b
green open .apm-agent-configuration 6FUF8T5oTDGcLBqcU7ymJg 1 0 0 0 283b 283b
This ability is mildly-buried/described-briefly in this section of the docs.

How can I filter through my groups/clusters to keep only the ones with different column2 values?

I have a file which looks something like this:
1 Ape 5138150 5140933
1 Ape 4289 7147
1 Ape 2680951 2683603
1 Ape 1484200 1486662
1 Baboon 3706008 3708636
1 Baboon 11745108 11747790
1 Baboon 3823683 3826474
2 Dog 216795245 216796748
2 Dog 14408 15922
3 Elephant 18 691
3 Ape 1 824
4 Frog 823145 826431
4 Sloth 35088 37788
4 Snake 1071033 1074121
5 Tiger 997421 1003284
5 Tiger 125725 131553
6 Tiger 2951524 2953649
6 Lion 178820 180879
Each group (or cluster) is indicated by the line number (e.g. all lines starting with 1 are in group 1) and different groups are separated by a blank line, as shown above. I'm interested in column 2. I want to keep all groups that have at least two different animals in column 2, but delete all groups that only have the one animal (i.e. species-specific groups). So with this file, I want to get rid of groups 2 and 5, but keep the others:
1 Ape 5138150 5140933
1 Ape 4289 7147
1 Ape 2680951 2683603
1 Ape 1484200 1486662
1 Baboon 3706008 3708636
1 Baboon 11745108 11747790
1 Baboon 3823683 3826474
3 Elephant 18 691
3 Ape 1 824
4 Frog 823145 826431
4 Sloth 35088 37788
4 Snake 1071033 1074121
6 Tiger 2951524 2953649
6 Lion 178820 180879
Is there a quick/easy way to do this? My actual file has over 10,000 different groups, so doing it manually is not a (sensible) option. I have a feeling I should be able to do this with awk, but no luck so far.
With GNU awk for length(array):
$ cat tst.awk
BEGIN { RS=""; ORS="\n\n"; FS="\n" }
{
delete keys
for (i=1; i<=NF; i++) {
split($i,f," ")
keys[f[2]]
}
}
length(keys) > 1
$ awk -f tst.awk file
1 Ape 5138150 5140933
1 Ape 4289 7147
1 Ape 2680951 2683603
1 Ape 1484200 1486662
1 Baboon 3706008 3708636
1 Baboon 11745108 11747790
1 Baboon 3823683 3826474
3 Elephant 18 691
3 Ape 1 824
4 Frog 823145 826431
4 Sloth 35088 37788
4 Snake 1071033 1074121
6 Tiger 2951524 2953649
6 Lion 178820 180879
You can solve it with python:
group = []
animals = set()
with open('data') as f:
for l in f:
line = l.strip()
if line == '':
if len(animals) > 1:
for g in group:
print g
print ''
group = []
animals = set()
continue
group.append(line)
animals.add(line.split()[1])
if len(animals) > 1:
for g in group:
print g
data is the name of your input file.
Explanation:
Iterate over every line of the file.
If the line is not a blank line, we add the line to the group to being able to print it later. Also, we add the second column to the animals distinct set.
If it is a blank line, we check whether we had more than one animal in the group. In that case we print all the lines of the group. In any case, we reset the group and animals since we are starting a new group.
The lines outside of the loop are required to write the last group if it contains more than one animal and if the file does not end with a blank line.

ActiveRecord::StatementInvalid: PG::InternalError expected "]" to end datum

I'm a newbie to Ruby and using ActiveRecord.
I'm trying to create a record (i.e. a new instance of a class) using ActiveRecord. I've already created and ran the migration, which created this file:
class CreatePeople < ActiveRecord::Migration
def change
create_table :people do |t|
t.string :first_name
t.string :last_name
t.datetime :birthdate
end
end
end
This is my model file with a class called Person in it:
class Person < ActiveRecord::Base
end
I went to the terminal and started the IRB console with the command "rake console." I tried the inputs: person = Person.new and person = Person.create(first_name: "Dave", last_name: "Smith"). Either input just gives me this error message:
ActiveRecord::StatementInvalid: PG::InternalError: ERROR: expected "]" to end datum,
but got "0 0 0 0 ]}) :location 2634}}
ETA (full error message):
ActiveRecord::StatementInvalid: PG::InternalError: ERROR: expected "]" to end datum,
but got "0 0 0 0 ]}) :location 2634}} :targetList ({TARGETENTRY :expr {VAR
:varno 4 :varattno 1 :vartype 19 :vartypmod -1 :varcollid 0 :varlevelsup 0
:varnoold 4 :varoattno 1 :location 2224} :resno 1 :resname schemaname
:ressortgroupref 0:resorigtbl 2615 :resorigcol 1: resjunk false}
{TARGETENTRY :expr {VAR :varno 3 :varattno 1 :vartype 19 :vartypmod -1
:varcollid 0 :varlevelsup 0 :varnoold 3: varattno 1 :location 2257} :resno 2
:resname tablename :ressortgroupref 0 :resorigtbl 1259 :resorigcol 1
:resjunk false} {TARGETENTRY :expr {FUNCEXPR :funcid 1645 :funcresulttype 19
:funcretset false :funcvariadic false :funcformat 0: funccollid 0
:inputcollid 0 :args ({VAR :varno 3: varattno 5 :vartype 26 :vartypmod -1
:varcollid 0 :varlevelsup 0 :varnoold 3 : varoattno 5 :location 2305})
:location 2289} :resno 3 :resname tableowner :ressortgroupref 0 :resorigtble
0 :resorigcol 0 :resjunk false} {TARGETENTRY :expr {VAR :varno 6 :varattno 1
:vartype 19 :vartypmod -1 :varcollid 0 :varlevelsup 0 :varnoold 6 : varattno
1 :location 2340} :resno 4 :resname tablespace :ressortgroupref 0
:resorigtble 1213 :resorigcol 1 :resjunk false} {TARGETENTRY :expr {VAR
:varno 3 :varttno 13 :vartype 16 :vartypmod -1 :varcollid 0 :varlevelsup 0
:varnoold 3 :varoattno 13 :location 2373} :resno 5 :resname hasindexes
:ressortgroupref 0 :resorigtble 1259 :resorigcol 13 :resjunk false}
{TARGETENTRY :expr {VAR :varno 3 :varattno 21 :vartype 16 :vartypmod -1
:varcollid 0 :varlevelsup 0 :varnoold 3 :varoattno 21 :location 2410} :resno
6 :resname hasrules :ressortgroupref 0 :resorigtble 1259 :resorigcol 21
:resjunk false} {TARGETENTRY :expr {VAR :varno 3 :varattno 22 :vartype 16
:vartypmod -1 :varcollid 0 :varlevels up 0 :varnoold 3 :varoattno 22
:location 2445} :resno 7 :resnmae hastriggers :ressortgroupref 0 :resorigtbl
1259 :resorigcol 22 :resjunk false}} :withCheckOptions <> :returningList <>
:groupClause <> :havingQual <> :windowCaluse <> :distinctClause <>
:sortClause <> :limitOffset <> :limitCount <> :rowMarks <> :setOperations <>
:constraintDeps <>})”; length = 1
LINE 2: FROM pg_tables
: SELECT TABLENAME
FROM pg_tables
WHERE schemaname = ANY (current_schemas(false))
from C:/Ruby200/lib/ruby/gems/2.0.0/gems/activerecord-4.2.1/lib/active_record
/connection_adapters/postgresql/database_statements.rb:147:in ‘async_exec’
from C:/Ruby200/lib/ruby/gems/2.0.0/gems/activerecord-4.2.1/lib/active_record
/connection_adapters/postgresql/database_statements.rb:147:in ‘block in query’
from C:/Ruby200/lib/ruby/gems/2.0.0/gems/activerecord-4.2.1/lib/active_record
/connection_adapters/abstract_adapter.rb:473: in ‘block in log’
from C:/Ruby200/lib/ruby/gems/2.0.0/gems/activesupport-4.2.1/lib
/active_support/notifications/instrumenter.rb:20:in ‘instrument’
from C:/Ruby200/lib/ruby/gems/2.0.0/gems/activerecord-4.2.1/lib/active_record
/connection_adapters/abstract_adapter.rb:467:in ‘log’
from C:/Ruby200/lib/ruby/gems/2.0.0/gems/activerecord-4.2.1/lib/active_record
/connection_adapters/postgresql/database_statements.rb:146:in ‘query’
From C:/Ruby200/lib/ruby/gems/2.0.0/gems/activerecord-4.2.1/lib/active_record
/connection_adapters/postgresql/schema_statements.rb:91:in ‘tables’
from C:/Ruby200/lib/ruby/gems/2.0.0/gems/activerecord-4.2.1/lib/active_record
/connection_adapters/schema_cache.rb:90:in ‘prepare_tables’
from C:/Ruby200/lib/ruby/gems/2.0.0/gems/activerecord-4.2.1/lib/active_record
/connection_adapters/schema_cache.rb:22:in ‘table_exists?’
From C:/Ruby200/lib/ruby/gems/2.0.0/gems/activerecord-4.2.1/lib/active_record
/model_schema.rb:230:in ‘table_exists?’
from C:/Ruby200/lib/ruby/gems/2.0.0/gems/activerecord-4.2.1/lib/active_record
/attribute_methods/primary_key.rb:97: in ‘get_primary_key’
from C:/Ruby200/lib/ruby/gems/2.0.0/gems/activerecord-4.2.1/lib/active_record
/attribute_methods/primary_key.rb:95:in ‘reset_primary_key’
from C:/Ruby200/lib/ruby/gems/2.0.0/gems/activerecord-4.2.1/lib/active_record
/connection_adapters/postgresql/
from C:/Ruby200/lib/ruby/gems/2.0.0/gems/activerecord-4.2.1/lib/active_record
/attribute_methods/primary_key.rb:73:in ‘primary_key’
from C:/Ruby200/lib/ruby/gems/2.0.0/gems/activerecord-4.2.1/lib/active_record
/model_schema.rb:234:in ‘attributes_builder’
from C:/Ruby200/lib/ruby/gems/2.0.0/gems/activerecord-4.2.1/lib/active_record
/model_schema.rb:254: in ‘_default_attributes’
from C:/Ruby200/lib/ruby/gems/2.0.0/gems/activerecord-4.2.1/lib/active_record
/core.rb:273:in ‘initialize’
from C:/Ruby200/lib/ruby/gems/2.0.0/gems/activerecord-4.2.1/lib/active_record
/inheritance.rb:61:in ‘new’
from C:/Ruby200/lib/ruby/gems/2.0.0/gems/activerecord-4.2.1/lib/active_record
/inheritance.rb:61:in ‘new’
As noted by m_x, there was an issue with the PG setup. There was no issue with ActiveRecord itself. In order to resolve this specific StatementInvalid Error, a full uninstall and reinstall needed to be performed for PostgreSQL.
It seemed like PostgreSQL's data folder got corrupted in some way. Just uninstalling using the Control Panel or the PostgreSQL uninstaller did not uninstall PostgreSQL completely. Specifically, PostgreSQL was not being uninstalled from the registry. This partial uninstall prevented a new data folder for PostgreSQL from being created with the correct bin and lib directories within it. These steps needed to be followed to get PostgreSQL to be uninstalled completely:
Uninstall PostgreSQL from control panel or the PostgreSQL
uninstaller from within the PostgreSQL directory.
Delete PostgreSQL directory folder
Run CCleaner to make sure old PostgreSQL registry keys are deleted. (free download available here: http://www.filehippo.com/download_ccleaner)
Download and reinstall PostgreSQL

Resources