CategoryEnglish

Switch configuration lines using comments

Continue reading

The meaning of “phlpwcspweb3” or why you should not do abbreviations in the code

“phlpwcspweb3”  is found at the “Amazon Web Services – Tagging Best Practices

From what I can decode from “phlpwcspweb3”  this is something related to web, and probably there are at least 3 instances of that kind.

According to AWS this should be meaningful hostname.

If you have decoded this you probably do not need to read further….

Continue reading

Running chef test-kitchen with newer vagrant

If you get

VBoxManage: error: The specified string / bytes buffer was to small. Specify a larger one and retry. (VERR_CFGM_NOT_ENOUGH_SPACE)

This means that the virtual machine needs a shorter name for the VM.

---
driver:
  name: vagrant
  customize:
    name: pdcsmb
    memory: 4144
    cpus: 4
  network:
    # - ["forwarded_port", {guest: 3000, host: 3000}]
    # - ["private_network", {ip: "192.168.33.33"}]

Bonus tip:

If you get

No live threads left. Deadlock?

Then remove all gems and reinstall chefdk.

Export database tables, fields comments as markup with Ruby on Rails

When you have to export the comments from the database you can use this short snippet to get the schema as markup.

content = ""
database_name = "DATABASE_NAME"
ActiveRecord::Base.connection.tables.each do |table_name|
  content << "h5. #{table_name}\n"
  rows = ActiveRecord::Base.connection.execute("SELECT table_comment 
    FROM INFORMATION_SCHEMA.TABLES 
    WHERE table_schema='#{database_name}' 
        AND table_name='#{table_name}';");
  puts rows.to_a.inspect
  content << rows.to_a.first.first << "\n"

  rows = ActiveRecord::Base.connection.execute("select table_name, column_name, DATA_TYPE, column_comment from INFORMATION_SCHEMA.COLUMNS where 1 AND TABLE_SCHEMA='#{database_name}' AND TABLE_NAME = '#{table_name}'")
  rows.each(:as => :hash) do |row| 
    puts row.inspect
    j = [ row["column_name"], row["DATA_TYPE"], row["column_comment"] ]

    content << "|#{j.join('|')}|\n"
  end
end; ''
puts content

The output should be something like

Table name

table description

column name, type, description

….. the next table

Running chef kitchen with cookbook dependencies

Berksfile

source 'https://supermarket.chef.io'

metadata

group :test do
  cookbook 'company_firewall', path: "../company_firewall"
  cookbook 'company_nginx', path: "../company_nginx"
  cookbook 'company', path: "../company"
  cookbook 'data-incoming', path: "../data-incoming"
  cookbook 'aws', path: "../aws"
end

metadata.rb

name             'data-listener'
maintainer       'Company'
maintainer_email 'sd@company.com'
license          'All rights reserved'
description      'Installs/Configures data-listener'
long_description IO.read(File.join(File.dirname(__FILE__), 'README.md'))
version          '0.2.32'

depends 'sysctl', '~> 1.0.5'
depends 'copany_firewall'
depends 'company_nginx'
depends 'aws'

 

mdadm: Duplicate MD device names in conf file where found.

remove the doublicate file from /etc/mdadm/mdadm.conf

cp mdadm.conf mdadm.conf.backup
grep -v "2 UUIDsomehing..." mdadm.conf.backup > mdadm.conf

Make sure the raid is up

mdadm --assemble --scan

Load the lvm volumes

lvm vgchange -ay
  • -a – activate
  • -y – complete

exit to try the changes

$(initramfs) exit

Now you system will boot

Making the changes permanent

Fix the /etc/mdadm/mdadm.conf file by removing the duplicate definition.

update-initramfs  -u -k all

If you are still in initramfs busybox

mkdir /target
mount /dev/md1 /target
mount -o bind /dev /target/dev
mount -o bind /proc /target/proc
mount -o bind /sys /target/sys
mount -o bind /dev/pts /target/dev/pts
chroot /target /bin/bash

Cheat

mdadm –detail /dev/md0 mdadm –detail /dev/md1

mdadm –detail –scan > /etc/mdadm/mdadm.conf

Stop an array & assemble array mdadm –stop /dev/md1

mdadm –assemble /dev/md0 /dev/sda1 /dev/sdb1 /dev/sdc1 /dev/sdd1 mdadm –assemble /dev/md1 /dev/sda2 /dev/sdb2 /dev/sdc2 /dev/sdd2

 

38693387_2127079967530580_4018998239729549312_n (1)

Tired of the old Rails scaffold?

Why Rails scaffold doesn’t work

The need to write a replacement of the Rails scaffold was because the build in one in Ruby on Rails:

  • Does not support namespaces on the controllers and the models it generates funny paths in the views and/or controllers
  • The native way to extend the Rails scaffold was changed frequently I have to spend hours tracing github issues
  • It uses the ugly scaffold.css and it generates it all the time breaking my styles
  • Does some freaky copy/paste optimizations in the controller to get the model. Scaffold should be a starting point from where with few deletes or add few lines of codes to make a usable screen.

The new approach

With scaffold_pico you can create your own pretty administration in a second.

  • No learning curve – if you know Rails you know it.
  • No 3rd party gems slowing your development/production startup times.
  • Clean code
  • Supports namespaces in the models and the controllers

There is also some sugar. With the pico_scaffold you can generate from the beginning fabricators and take care of N+1 by specifying joins/includes clauses. There is separation of the fields for index and editing. There is a search – almost every screen now days has search.

Supports Zurb Foundation, Materializecss CSS frameworks

Here is the github: https://github.com/gudata/scaffold_pico

Building docker image with host network aka –net=host

There is no option to provide the net as param while building the docker images.
So the container doesn’t have internet from inside.
and is common to get this kind of errors

Running in NNNNNNNNN
Err http://http.debian.net wheezy Release.gpg
  Could not resolve 'http.debian.net'

One (stupid) solution is to put in the Docker file

RUN echo "nameserver 8.8.8.8" > /etc/resolv.conf; cat /etc/resolv.conf

Another is to help Docker with the networking.

Here is a solution is pointed here

# Forward chain between docker0 and eth0
iptables -A FORWARD -i docker0 -o eth0 -j ACCEPT
iptables -A FORWARD -i eth0 -o docker0 -j ACCEPT
# IPv6 chain if needed
ip6tables -A FORWARD -i docker0 -o eth0 -j ACCEPT
ip6tables -A FORWARD -i eth0 -o docker0 -j ACCEPT

And also to configure docker to use a dns server as pointed here

Docker official doc gives instruments to Configure a DNS server for use by Docker

Open the /etc/default/docker file for editing.

$ sudo nano /etc/default/docker

Add a setting for Docker.

DOCKER_OPTS="--dns 8.8.8.8"

Replace 8.8.8.8 with a local DNS server such as 192.168.1.1. You can also specify multiple DNS servers. Separated them with spaces, for example:

–dns 8.8.8.8 –dns 192.168.1.1

Warning: If you’re doing this on a laptop which connects to various networks, make sure to choose a public DNS server.

ps: nm-tool can be used to check local host DNS server

Save and close the file.

Restart the Docker daemon.

$ sudo restart docker

Replacement for tilda guake or other not working solutions

This script will activate gnome-terminal when you press INSERT (the key right to backspace) and will hide it when pressed again.

Using this script is better than tilda or guake or whatever because you can resize the terminal. You can clean the terminal and have all goods you have in normal terminal.

To install it under lubuntu/lxde open ~/config/openbox/lubuntu-rc.xml and add

https://gist.github.com/gudata/4065ad9bb1fd6d82933b

Here is the code for the riseterminal.sh

#/bin/bash
XDO=/usr/bin/xdotool

#TERMINAL_ID=`$XDO  search --name Terminal | /usr/bin/tail -1`

raise_or_fall () {
  TERMINAL_ID=$($XDO search --class gnome-terminal | /usr/bin/tail -1)
  CURRENT_WINDOW_ID=`$XDO getwindowfocus`

  WIDS=`$XDO search --onlyvisible --class gnome-terminal`

  if [ "$CURRENT_WINDOW_ID" -eq "$WIDS" ]
  then
    # zenity --question --text="down"
    $XDO windowminimize $TERMINAL_ID
  else
    # zenity --question --text="up"
    # $XDO windowraise $TERMINAL_ID
    # $XDO windowfocus --sync $TERMINAL_ID
     $XDO windowactivate $TERMINAL_ID
  fi
}

if `ps aux | grep "[g]nome-terminal" > /dev/null`
then
  raise_or_fall
else
  gnome-terminal &
fi

Activeadmin

If you plan to use activeadmin you have to be warned that  by using active admin you are supporting two back ends – yours and the one for active admin.
So if you have time to work for someone else go with active admin. else just do it your self.
Don’t use it!
There is one rumor that nothing starting with active* was good product. ActiveDirectory for ActiveX…. I was wondering are there exceptions ActiveSupport, ActiveRecord….

© 2024 Gudasoft

Theme by Anders NorénUp ↑