LAZY Agnostic Application Generators (padrino-lazy)

Overview

Through padrino-lazy, we can include some common properties shared between the model object used a base model object

Padrino is very good framework, and almost follows the DRY principle (Donโ€™t Repeat Yourself) When we need to have some common properties shared between the model object of our ORM, using the generator padrino-gen, We can only include these properties in each model to generate.

I hope this idea will be included in Padrino Framework.
Principle / Step

  1. generate a model
  2. convert the model into base model ( move this model into lib/ folder)
  3. save config file with model baseโ€™s list
  4. generate a model from base model
  5. generate a migration file

Usage

Step 1-2-3

$ padrino-lazy base --c config_file --b base_model_name --f field_to_create

Step 4-5

$ padrino-lazy model --c config_file --b base_model_name --f field_to_create --m model_name

Install

gem install padrino-lazy --pre

Example

$ padrino-lazy base --c config --b BaseModel --f "create_at:datetime is_active:boolean"

now we have

lib/base_model.rb class BaseModel


include DataMapper::Resource

  # property ,
  property :id, Serial
  property :create_at, DateTime
  property :is_active, Boolean

end

config/config.yml


---
- base: BaseModel
fields: create_at:datetime is_active:boolean
$ padrino-lazy model --c config --b BaseModel --f "name:string have_children:boolean born:date foo:integer"  --m User

app/models/user.rb

class User <  BaseModel

  # property ,
  property :name, String
  property :have_children, Boolean
  property :born, Date
  property :foo, Integer
end

db/migrate/001_create_users.rb


migration 1, :create_users do
  up do
    create_table :users do
      column :id, Integer, :serial =&gt; true
      column :name, String
      column :have_children, Boolean
      column :born, Date
      column :foo, Integer
    end
  end

  down do
    drop_table :users
    end
  end

db/migrate/002_add_basic_model_to_user.rb


migration 2, :add_basic_model_to_user do
  up do
    modify_table :users do
      add_column :name, String
      add_column :have_children, Boolean
      add_column :born, Date
      add_column :foo, Integer
  end
end

down do
modify_table :users do
drop_column :name
drop_column :have_children
drop_column :born
drop_column :foo
end
end
end

Known issue

  • VERY VERY alpha code !! (thanks to my pig/lazy side ๐Ÿ˜€ )
  • โ€”f options need dobule quote around fields
  • โ€”b write in CamelCase
  • TESTING only with datamapper and activerecord into linux machine

TODO:

  • Test all code !
  • Use Padrino::Generators instead of Commander
  • Default config file name (very lazy ๐Ÿ˜› )

THANK

  • Team Padrino
  • DaddYE
  • Piedinodifata

CODE
https://github.com/WaYdotNET/padrino-lazy

automatic-screenshot-insertion-in-org

Original idea from http://emacsworld.blogspot.com/2011/05/automatic-screenshot-insertion-in-org.html

Original script using imagemagick:

Using scrot :

(defun org-screenshot ()
  "Take a screenshot into a time stamped unique-named file in the same directory as the org-buffer and insert a link to this file."
  (interactive)
  (setq filename
        (concat
         (make-temp-name
          (concat (buffer-file-name)
                  "_"
                  (format-time-string "%Y%m%d_%H%M%S_")) ) ".png"))
  (call-process "scrot" nil nil nil  "-s" filename)
  (insert (concat "[[" filename "]]"))
  (org-display-inline-images))

How to resize LVM logical volumes with ext4 as filesystem


# Unmount the filesystem and check its' LV
umount /mnt/foo
e2fsck -f /dev/mapper/vg0-foo

# Shrink ext4 and then the LV to the desired size
resize2fs -p /dev/mapper/vg0-foo 40G
lvreduce -L 40G /dev/mapper/vg0-foo

# Before continuing, run e2fsck. If it bails because the partition
# is too small, don't panic! The LV can still be extended with
# lvextend until e2fsck succeeds, e.g.:
# lvextend -L +1G /dev/mapper/vg0-foo
e2fsck -f /dev/mapper/vg0-foo

# Resize the filesystem to match the LVs size, check and mount it
resize2fs -p /dev/mapper/vg0-foo
e2fsck -f /dev/mapper/vg0-foo
mount /mnt/foo

umount /mnt/bar

# Extend the LV to use all free space
lvextend -l +100%FREE /dev/mapper/vg0-bar
e2fsck -f /dev/mapper/vg0-bar

# Resize the partition to fill the LV
resize2fs -p /dev/mapper/vg0-bar
e2fsck -f /dev/mapper/vg0-bar
mount /mnt/bar

source:
source

mini backup with rsync

#!/bin/bash
# Backup file remote/local
# By Carlo Bertini [WaYdotNET]
# il tutto utilizzando rsync senza scomodare subversion

# RSYNC OPTION 
# -r => ricorsivo
# -l => copy symlinks as symlinks
# -p => preserve permissions
# -v => verbose
# -u => update, ignorare i file che sono piรน nuovi nella destinazione
# -a => archive mode
# -z => comprime i file durante l invio
# -h => rendere leggibile l output
# --delete => cancello i file estranei nella destinazione

# il comando si deve chiamare con:
demo="sync_to_waydotnet [up or down] local_folder remote_folder" 

# VARIABILI
base="~/backup"
type=$1
local_folder=$2
remote_folder=$base/$3
host="HOST.EXT"
user="user"

if [ $type = "up" ] ; then
	echo "UPLOAD $local ==> $remote"	
	rsync -lrpuazhv --delete -e ssh $local_folder $user@$host:$remote_folder
elif [ $type = "down" ] ; then
	echo "DOWNLOAD ...... $remote ==> $local"
	rsync -lrpuazhv --delete -e ssh  $user@$host:$remote_folder $local_folder
else
	echo -e "la forma corretta da scrivere e' n $demo'"
fi
echo "Have a nice day :P"

how to highlight and bookmarks pdf files on linux

Because i need to highlight and bookmarks pdf file on linux/windows, only solution wich i’ve found is
Foxit Reader 3.3.1 for Windows

[UPDATE]
Foxit Reader 4.0 for Windows link 06/29/10

The linux version is too old and not have these function, but with wine work well (you need also mdac2.8 and jet4.0)

tips 4 me:
create foxit in $HOME/bin

#!/bin/sh
wine /home/waydotnet/wine_tools/Foxit Reader.exe $1

and

chmod +x foxit

If you found another solution, please comment ๐Ÿ˜€

Bye

Ubuntu 9.10 , run level 3 => installare driver Nvidia

Se dovete installare i nuovi driver Nvidia NVIDIA-Linux-x86_64-190.53-pkg2.run su ubuntu 9.10, dovete aver killato il server X …
Girovagando su internet ho trovato un modo veloce, che non conoscevo [visto che sono praticamente nuovo su linux], per poterlo fare

Tramite alt+ctrl+f1 entriamo in tty1 (conosole senza X)
ed immettiamo :

sudo /etc/init.d/gdm stop

poi potete installare tranuquillamente i driver Nvidia su vostro Ubuntu ๐Ÿ˜€

[SOLVED] log4r 1.1.4 & ruby 1.9.1 => GDC.rb and NDC.rb syntax error, unexpected ‘:’, expecting keyword_then or ‘;’ or ‘n’

EDIT: SOLVED , vedere commento ๐Ÿ˜€

log4r 1.1.4 & ruby 1.9.1 => GDC.rb and NDC.rb syntax error, unexpected ‘:’, expecting keyword_then or ‘;’ or ‘n’

GDC.rb

--- GDC.rb	Thu Jan 28 17:03:12 2010

+++ GDC.rb.new	Thu Jan 28 16:50:37 2010

@@ -13,10 +13,10 @@

     private_class_method :new

 

     def self.check_thread_instance()

-      if ( Thread.main != Thread.current ):

+      if ( Thread.main != Thread.current )

 	raise "Can only initialize Global Diagnostic Context from Thread.main" 

       else

-	if ( Thread.main[GDCNAME] == nil ):

+	if ( Thread.main[GDCNAME] == nil )

 	  Thread.main[GDCNAME] = $0

 	end

       end

line 19
repalce
if ( Thread.main[GDCNAME] == nil ):
with
if ( Thread.main[GDCNAME] == nil )

NDC.rb

--- NDC.rb	Thu Jan 28 17:03:09 2010

+++ NDC.rb.new	Thu Jan 28 16:51:35 2010

@@ -15,7 +15,7 @@

     private_class_method :new

 

     def self.check_thread_instance()

-      if ( Thread.current[NDCNAME] == nil ):

+      if ( Thread.current[NDCNAME] == nil )

 	Thread.current[NDCNAME] = Array.new

 	Thread.current[NDCNAMEMAXDEPTH] = NDCDEFAULTMAXDEPTH

       end

@@ -65,7 +65,7 @@

 

     def self.push( value )

       self.check_thread_instance()

-      if ( Thread.current[NDCNAME].length < Thread.current[NDCNAMEMAXDEPTH] ):		

+      if ( Thread.current[NDCNAME].length < Thread.current[NDCNAMEMAXDEPTH] )

 	Thread.current[NDCNAME].push( value )

       end

     end