Monday, April 2, 2012

Generic mysql database creation

 GRANT USAGE ON *.* TO database_a;  
 DROP USER database_a;  
 CREATE USER database_a IDENTIFIED BY 'password';  
 DROP DATABASE IF EXISTS database;  
 CREATE DATABASE database COLLATE utf8_general_ci;  
 GRANT ALL PRIVILEGES ON database.* TO database_a IDENTIFIED BY 'password';  
 FLUSH PRIVILEGES;  
 USE database;  

Thursday, February 2, 2012

How to obtain next id in mysql

SELECT Auto_increment FROM information_schema.tables WHERE table_name='the_table_you_want';

Wednesday, December 29, 2010

Custom ASP.NET control with inner properties

using System;
using System.Security.Permissions;
using System.ComponentModel;
using System.ComponentModel.Design;
using System.Drawing.Design;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Collections.Generic;

namespace aspnetCustom
{
    [TypeConverter(typeof(ExpandableObjectConverter)),]
    public class SubProperty
    {
        private string _Name = "";

        [DefaultValue(""), NotifyParentProperty(true),]
        public String Name
        {
            get
            {
                return this._Name;
            }
            set
            {
                this._Name = value;
            }
        }
    }

    [TypeConverter(typeof(ExpandableObjectConverter)),]
    public class Property
    {
        private string _Name = "";
        private List<SubProperty> _SubProperties = new List<SubProperty>();

        [DefaultValue(""), NotifyParentProperty(true),]
        public String Name
        {
            get
            {
                return this._Name;
            }
            set
            {
                this._Name = value;
            }
        }

        [DesignerSerializationVisibility(DesignerSerializationVisibility.Content), Editor(typeof(CollectionEditor), typeof(UITypeEditor)), PersistenceMode(PersistenceMode.InnerProperty),]
        public List<SubProperty> SubProperties
        {
            get
            {
                return this._SubProperties;
            }
        }
    }

    [AspNetHostingPermission(SecurityAction.Demand, Level = AspNetHostingPermissionLevel.Minimal), AspNetHostingPermission(SecurityAction.InheritanceDemand, Level = AspNetHostingPermissionLevel.Minimal),]
    public class Control : WebControl
    {
        private List<Property> _Properties = new List<Property>();
        [DesignerSerializationVisibility(DesignerSerializationVisibility.Content), Editor(typeof(CollectionEditor), typeof(UITypeEditor)), PersistenceMode(PersistenceMode.InnerProperty),]
        public List<Property> Properties
        {
            get
            {
                return this._Properties;
            }
        }

        protected override void RenderContents(HtmlTextWriter writer)
        {
            if (this.DesignMode)
                writer.WriteLine("Control");
        }
    }
}

Tuesday, August 10, 2010

Twitter speaking in Ubuntu


#!/bin/bash
if [ $# -eq 0 ];
then
    User=????????
    Password=????????
    Url=https://twitter.com/statuses/home_timeline.xml
    Command="bash $0 \""
    curl -u $User:$Password $Url -s | \
    grep "<text>" | \
    sed "s/<text>/$Command/g" | \
    sed 's/<\/text>/"/g' | \
    bash
else
    file=$(echo "$1" | md5sum | awk '{print $1}')
    if [ ! -d ~/.twitter ];
    then
        mkdir ~/.twitter
    fi
    if [ ! -f ~/.twitter/$file ];
    then
        touch ~/.twitter/$file
        echo "$1"
        espeak "$1"
    fi
fi