+++ /dev/null
-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
-}
--- /dev/null
+# 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 \"$@\""
+}
*/
function query($sql) {
+ return $this->query2v($sql);
return $this->conn->query($sql);
}
return $this->conn->quote($v);
}
+ function table($name) {
+ return new Table($name,array('db'=>$this));
+ }
+
function tables() {
if ($this->tables) return $this->tables;
public $type = 'text';
public $default = null;
public $key = false;
+ public $autoinc = false;
function __construct($name,$attr=array()) {
$this->name = $name;
<?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);
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
*
$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,