]> git.nbdom.net Git - nb.git/commitdiff
mac.sh, libs
authorNicolas Boisselier <nicolas.boisselier@gmail.com>
Tue, 21 Jul 2015 09:33:24 +0000 (10:33 +0100)
committerNicolas Boisselier <nicolas.boisselier@gmail.com>
Tue, 21 Jul 2015 09:33:24 +0000 (10:33 +0100)
etc/profile.d/darwin.sh [deleted file]
etc/profile.d/mac.sh [new file with mode: 0644]
lib/php/db.php
lib/php/db/field.php
lib/php/db/table.php

diff --git a/etc/profile.d/darwin.sh b/etc/profile.d/darwin.sh
deleted file mode 100644 (file)
index ac6fbbf..0000000
+++ /dev/null
@@ -1,21 +0,0 @@
-mac_pbcopy() {
-  cat $@ | ssh -q $1 -o 'ForwardAgent yes' 'cat|pbcopy'
-}
-[ -z "$DARWIN" ] && return 0
-
-md5sum() {
-  md5 $@ | sed "s/^MD5 (\(.*\)) = \(.*\)$/\2  \1/"
-}
-
-mac_xmessage() {
-  osascript -e "tell app \"System Events\" to display dialog \"$@\""
-}
-
-mac_config() {
-  echo "Finder path           : YES"
-  defaults write com.apple.finder _FXShowPosixPathInTitle -bool YES
-  echo "Finder quit           : YES"
-  defaults write com.apple.finder QuitMenuItem -bool YES
-  echo "Finder show all files : FALSE"
-  defaults write com.apple.finder AppleShowAllFiles FALSE
-}
diff --git a/etc/profile.d/mac.sh b/etc/profile.d/mac.sh
new file mode 100644 (file)
index 0000000..849918b
--- /dev/null
@@ -0,0 +1,46 @@
+# See: http://www.infoworld.com/article/2614879/mac-os-x/top-20-os-x-command-line-secrets-for-power-users.html
+mac_pbcopy() {
+  cat $@ | ssh -q $1 -o 'ForwardAgent yes' 'cat|pbcopy'
+}
+[ -z "$DARWIN" ] && return 0
+
+[ -x /opt/local/bin/mysqld_safe5 ] && alias mac_mysqlstart='sudo /opt/local/bin/mysqld_safe5 &'
+[ -x /opt/local/bin/mysqladmin5 ] && alias mac_mysqlstop='/opt/local/bin/mysqladmin5 -u _mysql -p shutdown'
+[ -x /Applications/iTunes.app/Contents/MacOS/iTunes ] && alias iTunes=/Applications/iTunes.app/Contents/MacOS/iTunes
+[ -x /Applications/VLC.app/Contents/MacOS/VLC ] && alias vlc=/Applications/VLC.app/Contents/MacOS/VLC
+
+alias mac_vlc_playlists='open -a vlc --args /home/nico/Music/*/*.m3u'
+alias mac_top_proc="echo 'TOP PROCESSES:'; ps -Aro'%cpu, ucomm, user' | grep root | grep -v ' 0.0 '"
+alias mac_sleep='pmset sleepnow'
+alias mac_mount_nfs='sudo mount -o resvport -t nfs'
+alias mac_automount='sudo automount -v'
+alias mac_dns_flush='sudo dscacheutil -flushcache'
+alias mac_halt='halt=1 && bash -c "(sleep 3 && halt) &" && logout'
+
+mac_config() {
+  declare run r; run="
+echo 'Finder path           : YES'
+defaults write com.apple.finder _FXShowPosixPathInTitle -bool YES
+echo 'Finder quit           : YES'
+defaults write com.apple.finder QuitMenuItem -bool YES
+echo 'Finder show all files : FALSE'
+defaults write com.apple.finder AppleShowAllFiles FALSE
+"
+  echo "$run"
+  read -p "Run (y)?: " r
+  [ "$r" = "y" ] || return 1
+  echo "$run" | sh
+}
+
+mac_user_top_proci() {
+  echo "TOP PROCESSES:"
+  ps -Aro'%cpu, ucomm, user' | grep `whoami` | grep -v ' 0.0 '
+}
+
+md5sum() {
+  md5 $@ | sed "s/^MD5 (\(.*\)) = \(.*\)$/\2  \1/"
+}
+
+mac_xmessage() {
+  osascript -e "tell app \"System Events\" to display dialog \"$@\""
+}
index f53e35d84f366b49dede2d5cd45f2bc7f85fbaea..631ed66e39de4c4f6eb39b6652c5460f1174cae3 100644 (file)
@@ -88,6 +88,7 @@ class db {
 */
 
   function query($sql) {
+    return $this->query2v($sql);
     return $this->conn->query($sql);
   }
 
@@ -118,6 +119,10 @@ class db {
     return $this->conn->quote($v);
   }
 
+  function table($name) {
+    return new Table($name,array('db'=>$this));
+  }
+
   function tables() {
     if ($this->tables) return $this->tables;
 
index e8fc03f930e2a4b444eae1f80e0c462698bb64a8..7f947e20d30e47edc4e8e614d60f39aee687e916 100644 (file)
@@ -6,6 +6,7 @@ class field {
   public $type = 'text';
   public $default = null;
   public $key = false;
+  public $autoinc = false;
 
   function __construct($name,$attr=array()) {
     $this->name = $name;
index 24f9cc59bbd81dab41523487e96e9bb0f0805cb4..56c3dbcc7ca5c7d1559ec1b8ca29a93786187875 100644 (file)
@@ -1,5 +1,17 @@
 <?php
 require_once(dirname(__FILE__).'/../functions.php');
+require_once(dirname(__FILE__).'/../db.php');
+
+if (empty($_SERVER['DOCUMENT_ROOT'])) {
+  $_REQUEST['db'] = 'rent'; $name = 'tenant';
+  $_REQUEST['db'] = 'rt'; $name = 'classes';
+  require_once('/opt/rent/www/config/db.php');
+  #$db = new db('mysql:host=big;port=3306;dbname=rent;user=nico;password=');
+  print_r($Db->tables());
+  $Table = $Db->table($name);
+  print_r($Table->sql());
+}
+
 if (!defined('DB_HTML_EDIT')) define('DB_HTML_EDIT','Edit');
 if (!defined('DB_HTML_DELETE')) define('DB_HTML_DELETE','Delete');
 if (!defined('DB_HTML_NAV_TOP')) define('DB_HTML_NAV_TOP','<div align="center" class="nav" id="nav_top"></div>'.PHP_EOL);
@@ -41,6 +53,25 @@ class table {
     return $this->fields();
   }
 
+  /*
+   * Function db.sql
+   *
+   * return the sql to create the table
+   *
+   */
+  function sql() {
+    if ($this->db->type == 'sqlite') {
+      $sql = "SELECT sql FROM sqlite_master WHERE name='$this->name'";
+    } elseif ($this->db->type == 'mysql') {
+      $sql = "SHOW CREATE TABLE `$this->name`";
+    } elseif ($this->db->type == 'pgsql') {
+      $sql = "SELECT show_create_table('$this->name')";
+    } else {
+      err('table.sql(): Unknow db type: '.$this->db->type);
+    }
+    return $this->db->query($sql);
+  }
+
   /*
    * Function db.fields
    *
@@ -57,7 +88,7 @@ class table {
         $sql = "PRAGMA table_info('$this->name')";
 
       } elseif ($this->db->type == 'pgsql') {
-$sql = "SELECT
+        $sql = "SELECT
 a.attname AS name,
 pg_catalog.format_type(a.atttypid, a.atttypmod) AS type,
 CASE a.attnotnull WHEN 't' then 1 ELSE 0 END AS notnull,