Never been to CodeSnippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world (or not, you can keep them private!)

Codeingniter server path config

viagra ohne rezept viagra viagra ordnung in deutschland besten preis viagra viagra
kaufen cialis deutschland lieferung cialis cialis online ohne rezept cialis kaufen pillen gegen impotenz
|---------------------------------------------------------------
| SET THE SERVER PATH
|---------------------------------------------------------------
|
| Let's attempt to determine the full-server path to the "system"
| folder in order to reduce the possibility of path problems.
|
*/
if (function_exists('realpath') AND @realpath(dirname(__FILE__)) !== FALSE) {
	$index_path=str_replace("\\", "/", realpath(dirname(__FILE__)));
	$FILE=__FILE__;
}
if (file_exists($index_path."/codeigniter")!=true){
	$FILE=$_SERVER['SCRIPT_FILENAME'];
	$index_path=realpath(dirname($_SERVER['SCRIPT_FILENAME']));
}
$system_folder=$index_path.'/'.$system_folder;


gut preis levitra deutschland impotenz deutschland levitra levitra diskont online levitra deutschland
kamagra ubernachtung besten preis gut preis kamagra kamagra kamagra kaufen kamagra generika

Django: adding new admin_tags

// First: create a file under djangoapp/templatetags where you define your tags [e.g.: myadmin_tags.py]:


from django import template 
from poms.pomsapp import models

register = template.Library() 

# for People template

@register.inclusion_tag('admin/snippets/personfactoid_info.html') 
def display_personfactoids(person_id): 
    person = models.Person.objects.get(id__exact=person_id) 
    # factoids = models.Factoids.objects.filter(people=person)
    return { 'person': person }


// Second: create the html snippets that get loaded in those tags [e.g., personfactoid_info.html]:


{% if person.assocfactoidperson_set.all %}

<b>Person associated to factoids:</b></br />

	<table>
	  <tr>
	    <th>Record ID</th>
		<th>Type</th>
	    <th>Short Summary</th>
		<th>Role</th>
	    <th>Source</th>
	  </tr>

	{% for a in person.assocfactoidperson_set.all %}
	  <tr>
	    <td>{{a.factoid.id}}</td>
		<td>{{a.factoid.get_right_subclass.0}}&#160;&#160;&#160;&#160;</td>
	    <td><a href="{% url factoid_detail a.factoid.id %}" title="click to show">{{a.factoid}}</a></td>
	    <td>{{a.role}}</td>
	    <td><a href="{% url source_detail a.factoid.sourcekey.id %}" title="click to show">{{a.factoid.sourcekey}}</a></td>
	  </tr>
	{% endfor %}

	</table>
	
	<br /><hr><hr><hr><br />
{% endif %}	



// Third: in mytemplates/admin/ modify change_form.html (if you don't have it just copy it from the django-admin app). You must add a placeholder for the new templatetags (probably you want to add it at the bottom of the page):


........

{% block related_items_block %}{% endblock %}

........




// FOurth: create a new change_form.html in the same directory as above, but under your model template [e.g., mytemplates/admin/myapp/mymodel/change_form.html] so to override the behaviour just for that. The 'object_id' variable is passed by the admin template by default:


{% extends "admin/change_form.html" %} 
{% load myadmin_tags %} 
{% block related_items_block %}
<h2>Additional information:</h2><br />

  	{% if object_id %}
		{% display_personfactoids object_id %}
	{% endif %} 
	
 {% endblock %}


Modificar, eliminar, publicar

Shortcut para el link "Modificar" en las listas del admin.

function lnkModificar($href){
    return Tags::A("class='ico ico-page_white_edit' href='$href'",'Modificar');
}


Requiere class jtTags.

*lnkEliminar* coloca el link para eliminar mediante ajax, a partir del contenido del href:

function lnkEliminar($href){
    return Tags::A("href='$href' name='eliminar' class='ico ico-delete'",'Eliminar');
}
// ejemplo:
echo lnkEliminar('eliminar_articulo=25');


function lnkPublicar($href,$pub='Y'){
    $css_ico = ($pub=='Y') ? 'ico-tick' : 'ico-cross' ;
    $setpub = ($pub=='Y') ? 'N' : 'Y' ;
    return Tags::A("class='ico $css_ico' href='$href&pub=$setpub' name='publicar'",'&nbsp;');
}

Class jtForms

Conjunto de funciones estáticas para generar código de elementos de un form.

class Forms extends Tags{

    static function Form($name=NULL,$action=NULL,$attr=NULL,$txt=NULL){
        return parent::Tag(
            'form',
            self::Attr('method','post') . self::Attr('action', $action) . 
            self::Attr('enctype','multipart/form-data') . self::Name($name) . $attr,
            parent::Table(NULL,$txt) . self::Hidden('accion',$name)
        );
    }
    static function Linea($label=null,$txt=null, $attr=null){
        return parent::Tr($attr, parent::Td("class='label'",$label) . parent::Td(null,$txt) ) ;
    }
    static function Label($name=NULL,$txt=NULL){
        return ($txt) ? parent::Tag('label', self::Attr('for',$name), $txt) : NULL ;
    }
    static function Input($type='text',$name=null,$label=null,$value=null,$attr=null,$attrExtra=null){
        if($type=='text' || $type=='password' || $type=='file')
            return self::Linea(
                self::Label($name,$label) ,
                parent::Tag('input', self::Type($type) . self::Name($name) . self::Value($value) . $attr, null, true) ,
                $attrExtra
            );
        if($type=='radio' || $type=='submit' || $type=='hidden' || $type=='checkbox')
            return parent::Tag('input', self::Type($type) . self::Name($name) . self::Value($value) . $attr, null, true);
    }

    // tipos de input
    static function Text($name=null,$label=null,$value=null,$attr=null,$attrExtra=null){
        return self::Input('text',$name,$label,$value,$attr,$attrExtra);
    }
    static function Hidden($name=null,$value=null){
        if($name) return self::Input('hidden',$name,null,$value);
    }
    static function Textarea($name=null,$label=null,$value=null,$attr=null,$attrExtra=null){
        return self::Linea(
            self::Label($name,$label),
            parent::Tag('textarea', self::Name($name) . $attr, $value),
            $attrExtra
        );
    }
    static function Checkbox($name=null,$value=null,$attr=null,$checked=null,$label=NULL){
        $checked = ($value==$checked) ? self::Attr('checked','checked') : null;
        $checkbox = parent::Tag('input',self::Name($name) . self::Type('checkbox'). self::Value($value) . $checked . $attr, null, true);
        if($label) $checkbox = "<label>$checkbox $label</label>";
        return $checkbox;

    }
    static function Password($name=null,$label=null,$value=null,$attr=null,$attrExtra=null){
        if($name) return self::Input('password',$name,$label,$value,$attr,$attrExtra);
    }
    static function File($name=NULL,$label=null,$attr=NULL,$attrExtra=NULL){
        if($name) return self::Input('file',$name,$label,null,$attr,$attrExtra);
    }

    static function Select($name,$label=NULL,$values=NULL,$value=NULL,$attr=null,$attrExtra=NULL){
        if($name && $values){
            $options = null;
            foreach($values as $k=>$v){
                $op_attr = ($k==$value) ? self::Attr('selected','selected') : NULL ;
                $op_attr.= self::Value($k);
                $options.= parent::Tag('option',$op_attr,$v);
            }
            $select = parent::Tag('select', self::Name($name) . $attr,$options);
            return self::Linea(self::Label($name,$label),$select,$attrExtra);
        }
    }
    // elementos discretos
    static function Submit($value='Guardar'){
        if($value) return self::Input('submit','submit',NULL,$value,self::Attr('class','boton submit') );
    }
    static function Cancelar($txt='Cancelar',$href='javascript:history.go(-1);'){
        if($txt) return parent::A( self::Attr('href',$href) . self::Attr('class','cancelar'), $txt);
    }
    static function Button($name=null,$value=null){
        return parent::Tag('input', self::Type('button') . self::Name($name) . self::Value($value) . self::Attr('class','boton') );
    }

    // atributos
    private static function Name($name=null){ return self::Attr('name',$name) . self::Attr('id',$name) ; }
    private static function Type($type=null){ return self::Attr('type',$type); }
    private static function Value($value=null){ return self::Attr('value',$value); }
    private static function Attr($name=null,$value=null){
        if($name && isset($value)) return "$name='$value' ";
    }

    // combinaciones (atajos)
    static function qSubmit($id=NULL, $txt_submit='Guardar'){
        $id = ($id) ? self::Hidden('id',$id) : NULL;
        return self::Linea( NULL,
            $id . self::Submit($txt_submit) , "class='separador'"
        );
    }
    static function qSubmit2($id=NULL, $txt_submit='Guardar', $txt_cancelar='Cancelar'){
        $id = ($id) ? self::Hidden('id',$id) : NULL;
        return self::Linea(
            NULL,
            $id . self::Submit($txt_submit) . self::Cancelar($txt_cancelar) , "class='separador'"
        );
    }
    static function qSubmit3($id=null,$txt_submit='Guardar',$txt_cancelar='Cancelar',$txt_eliminar='Eliminar'){
        $id = ($id) ? self::Hidden('id',$id) : NULL;
        $btn_eliminar = self::Input('submit','eliminar',NULL,$txt_eliminar," class='boton submit' style='float:right'");
        return self::Linea(
            NULL,
            $btn_eliminar . $id . self::Submit($txt_submit) . self::Cancelar($txt_cancelar) , "class='separador'"
        );
    }

    // selector múltiple, mediante option y/o checkbox
    // recibe un array con todas las opciones y otro con las seleccionadas
    static function SelectorMultiple($tipo=NULL,$name=NULL,$label=NULL,$values=NULL,$values_sel=NULL,$attr=NULL,$attrContenedor=NULL){
        $elementos = NULL;
        if($values && is_array($values)){
            foreach($values as $k=>$v){
                $selected = NULL;
                $checked = NULL;
                if ((!is_array($values_sel) && ($k==$values_sel)) || (is_array($values_sel) && in_array($k,$values_sel)) ) {
                    $selected = self::Attr('selected','selected');
                    $checked = self::Attr('checked','checked');
                }
                if($tipo=='select' || $tipo=='option'){
                    $elementos.= "<option value='$k' $selected>$v</option>";
                }
                if($tipo=='checkbox' || $tipo=='radio'){
                    $elementos.= "<label style='padding-right:8px;'>".
                        parent::Tag('input',self::Type($tipo).self::Name($name).
                        self::Value($k).$checked, ' &nbsp;'.$v, true)."</label>";
                }
            }
        }
        if($tipo=='select' || $tipo=='option'){
            return self::Linea(self::Label($name,$label), parent::Tag('select',self::Name($name) . 
                   $attr." multiple='multiple' ",$elementos), $attrContenedor);
        }
        if($tipo=='checkbox' || $tipo=='radio'){
            return self::Linea(self::Label($name,$label), $elementos, $attrContenedor );
        }
    }
}

change mysql user password

From terminal (square brackets denote your input, do not actually include the brackets):

mysqladmin -u [user] -h localhost -p password '[new_password]'

Creating & deleting system service agent accounts on Mac OS X

Inspired by: Description and guidelines on creating system service agent accounts on Mac OS X (Tiger) and HiddenAdminCreate

Use at your own risk!

1. create a system service agent account


#!/bin/bash

if [[ "$(/usr/bin/whoami)" != "root" ]]; then printf '\nMust be run as root!\n\n'; exit 1; fi

OPATH=$PATH
export PATH=/usr/bin:/usr/sbin:/bin:/sbin

OIFS=$IFS
export IFS=$' \t\n'

printf '\n\e[1mYou are going to create a system service agent account!\e[m\n\n'

declare sudo=/usr/bin/sudo dscl=/usr/bin/dscl


# first name 

printf "\e[1mEnter first name\e[m: "
read fn

# no spaces in names
if [[ -z "$(printf -- "$fn" | /usr/bin/grep -Eo "^[^[:space:]]+$")" ]]; then
   printf '\nUse a name without spaces! \nPlease, try again!\n\n'
   exit 1
fi

# name must not begin with a number
if [[ -n "$(printf -- "$fn" | /usr/bin/grep -E "^[[:digit:]]")" ]]; then
   printf '\nName must not begin with a number! \nPlease, try again!\n\n'
   exit 1
fi


# make sure the user name is unique
new_user="$(/usr/bin/dscl . -search /Users name "$fn" 2>/dev/null)"

if [[ -z "$new_user" ]]; then
  new_user="$fn"               
else
  printf "\nUser name already exists: $fn \nPlease, modify your name and try it again\x21\n\n"
  exit 1
fi 


# make sure the agent's primary group name is unique 
# note: the agent's primary group name is also based on the first name!

new_group="$(/usr/bin/dscl . -search /Groups name "$fn")"

if [[ -z "$new_group" ]]; then
  new_group="$fn"             
else
  printf "\nThe agent's primary group name already exists: $fn\x21 \nPlease, try again\x21\n\n"
  exit 1
fi 


# last name

printf '\nNote: The \e[1mlast name\e[m is \e[1moptional\e[m and defaults to "agent" if you just press <return>!\n'
printf "\e[1mEnter last name\e[m: "
read ln

if [[ -z "$ln" ]]; then ln="agent"; fi

# no spaces in names
if [[ -z "$(printf -- "$ln" | /usr/bin/grep -Eo "^[^[:space:]]+$")" ]]; then
   printf '\nUse a name without spaces! \nPlease, try again!\n\n'
   exit 1
fi

# name must not begin with a number
if [[ -n "$(printf -- "$ln" | /usr/bin/grep -E "^[[:digit:]]")" ]]; then
   printf '\nName must not begin with a number! \nPlease, try again!\n\n'
   exit 1
fi


# user shell

printf '\nNote: The \e[1muser shell\e[m is \e[1moptional\e[m and defaults to "/usr/bin/false" if you just press <return>!\n'
printf "\e[1mEnter user shell\e[m: "
read sh

if [[ -z "$sh" ]]; then sh="/usr/bin/false"; fi

# test if user shell exists
if [[ ! -e "$sh" ]]; then
   printf "\nUser shell does not exist: $sh\n\n"
   exit 1
fi


# home directory

printf '\nNote: The \e[1mhome directory\e[m is \e[1moptional\e[m and defaults to "/private/var/empty" if you just press <return>!\n'
printf "\e[1mEnter home directory\e[m: "
read hd

if [[ -z "$hd" ]]; then 
   hd="/private/var/empty"
elif [[ "${hd:0:1}" != '/' ]]; then
   printf '\nThe home directory path does not begin with a slash "/".\nPlease, try again!\n\n'
   exit 1
elif [[ -e "$hd" ]]; then
   printf "\nHome directory already exists: $hd \nPlease, try again\x21\n\n"
   exit 1
fi

hd=${hd%/}      # remove a trailing slash character "/" if necessary



# get unique id numbers (uid, gid)
unset -v new_uid new_gid i
declare -i new_uid=0 new_gid=0 i=100

while [[ $i -lt 500 ]]; do      # try to get $new_uid and $new_gid between 100 and 500
   i=$[i+1]
   if [[ -z "$(/usr/bin/dscl . -search /Users uid $i)" ]] && [[ -z "$(/usr/bin/dscl . -search /Groups gid $i)" ]]; then
      new_uid=$i
      new_gid=$i
      break
   fi
done


if [[ $new_uid -eq 0 ]] || [[ $new_gid -eq 0 ]]; then     # get $new_uid and $new_gid greater than 500
   i=500
   idvar=0

   while [[ $idvar -eq 0 ]]; do 
      i=$[i+1]
      if [[ -z "$(/usr/bin/dscl . -search /Users uid $i)" ]] && [[ -z "$(/usr/bin/dscl . -search /Groups gid $i)" ]]; then
         new_uid=$i
         new_gid=$i
         idvar=1
         #break
      fi
   done

fi


if [[ $new_uid -eq 0 ]] || [[ $new_gid -eq 0 ]]; then printf 'Getting unique id numbers (uid, gid) failed!\n'; exit 1; fi



# check once again ...

if [[ $new_uid -eq $new_gid ]] && [[ "$new_user" == "$fn" ]] && [[ "$new_group" == "$fn" ]]; then

# create home directory
if [[ "$hd" != "/private/var/empty" ]]; then
   $sudo /bin/mkdir -p "$hd"
fi

# create the agent's primary group
$sudo /usr/sbin/dseditgroup -o create -r "$fn $ln" -i $new_gid "$new_group"
$sudo $dscl  . -append "/Groups/$new_group" passwd "*"

# create the system service agent
$sudo $dscl . -create /Users/$new_user
$sudo $dscl . -append /Users/$new_user RealName "$fn $ln"
$sudo $dscl . -append /Users/$new_user uid $new_uid
$sudo $dscl . -append /Users/$new_user gid $new_gid
$sudo $dscl . -append /Users/$new_user shell "$sh"
$sudo $dscl . -append /Users/$new_user home "$hd"
$sudo $dscl . -create /Users/$new_user passwd "*"

$sudo $dscl  . -append "/Groups/$new_group" GroupMembership "$new_user"    # add new agent to the agent's primary group
#$sudo /usr/sbin/dseditgroup -o edit -a "$new_group" -t user "$new_user"

else

   printf "\nConfiguration of system service agent account: $fn failed\x21 \nPlease, try again\x21\n\n"
   exit 1

fi

# create further subdirectories if necessary
#if [[ "$hd" != "/private/var/empty" ]]; then
#
#if [[ "$new_user" == "clamavadmin" ]]; then
#   # additional subdirectories for the clamavadmin system service agent account
#   $sudo /bin/mkdir  -p "$hd"/log
#   $sudo /usr/bin/touch "$hd"/log/clamd.log
#   $sudo /bin/mkdir  -p "$hd"/tmp
#   $sudo /bin/mkdir  -p "$hd"/share/clamav
#   $sudo /usr/sbin/chown -R $new_user:$new_user "$hd"
#   $sudo /bin/chmod -R 750 "$hd"
#fi
#
#fi


printf "\nSystem service agent account:  \e[1m$fn\e[m  successfully created\x21\n\n"

export IFS=$OIFS
export PATH=$OPATH

exit 0


#---------------------------

# test
dscl . list /Users
dscl . -read /Users/<first name>

dscl . list /Groups
dscl . -read /Groups/<first name>
dscl . list /Groups GroupMembership



2. delete a system service agent account

#!/bin/bash


if [[ "$(/usr/bin/whoami)" != "root" ]]; then printf '\nMust be run as root!\n\n'; exit 1; fi

OPATH=$PATH
export PATH=/usr/bin:/usr/sbin:/bin:/sbin

OIFS=$IFS
export IFS=$' \t\n'

declare sudo=/usr/bin/sudo


printf "\n\e[1mDelete system service agent account\e[m: "
read agent

if [[ -z "$agent" ]]; then printf '\nNo name for system service agent specified! Please, try again!\n\n'; exit 1; fi

# make sure the agent exists
agenttest="$(/usr/bin/dscl . -search /Users name "$agent")"

if [[ -z "$agenttest" ]]; then printf "\nThe system service agent does not exist: $agent\n\n"; exit 1; fi 


# find the agent's home directory
home=$(/usr/bin/dscl . -read /Users/$agent home | awk -F ': ' '{ print $NF; }' )


# get the agent's group memberships
groups_of_agent="$(/usr/bin/id -Gn $agent)"

# delete the agent's group memberships
if [[ $? -eq 0 ]] && [[ -n "$(/usr/bin/dscl . -search /Groups GroupMembership "$agent")" ]]; then

   for group in $groups_of_agent; do
      $sudo /usr/bin/dscl . -delete "/Groups/$group"  GroupMembership "$agent"
      #$sudo /usr/sbin/dseditgroup -o edit -d "$agent" -t user "$group"           
   done

fi


# delete the agent's primary group
if [[ -n "$(/usr/bin/dscl . -search /Groups name "$agent")" ]]; then
   $sudo /usr/sbin/dseditgroup -o delete "$agent"
fi

# if the agent's primary group has not been deleted ...
if [[ -n "$(/usr/bin/dscl . -search /Groups name "$agent")" ]]; then
printf "
   \e[1mWarning\e[m:
   The group memberships of the system service agent \e[1m$agent\e[m have been deleted\x21
   groups_of_agent: $groups_of_agent
   The agent's primary group \e[1m$agent\e[m, however, has not been deleted\x21
   Please, try again\x21
   Exiting ...\n
"
  exit 1
fi


# find the GeneratedUID of the agent and remove the password hash file 
# from /private/var/db/shadow/hash/<GeneratedUID>
# sudo ls -a /private/var/db/shadow/hash
# sudo ls -l /private/var/db/shadow/hash/<GeneratedUID>

guid="$(/usr/bin/dscl . -read "/Users/$agent" GeneratedUID | /usr/bin/awk '{print $NF;}')"

if [[ -f "/private/var/db/shadow/hash/$guid" ]]; then
   $sudo /bin/rm -f /private/var/db/shadow/hash/$guid
fi


# delete the agent
$sudo /usr/bin/dscl . -delete "/Users/$agent"

# make a backup
if [[ -d "$home" ]] && [[ "$home" != "/private/var/empty" ]]; then
   $sudo /usr/bin/ditto -rsrc -c -k "$home" "${home}-archive-$(/bin/date).zip"
fi

# remove the agent's home directory
if [[ -d "$home" ]] && [[ "$home" != "/private/var/empty" ]]; then
   $sudo /bin/rm -rf "$home"
fi


printf "\nSystem service agent account:  \e[1m$agent\e[m  successfully deleted\x21\n\n"


export IFS=$OIFS
export PATH=$OPATH

exit 0