Pages

Monday, February 28, 2011

Drupal Theme - iPad Them

file ipad.info
name = iPad Theme
description = This is just affect style only
core = 7.x
package = Apple
engine = phptemplate
stylesheets[all][] = style.css

file style.css
/**
 * This theme just theming the drupal base system because
 * these module doesn't have any template file
 *
 * @name    : iPad Theme
 * @author  : irfanudin ridho
 * @email   : irfan.ub@gmail.com
 * @version : 1.0
 * @date    : March 1, 2011
 */


Web App - Coloring V2

<div id="page">
<div id="satu">For the last moment we get from here</div>
<table>
<tr><td>Foreground</td></tr>
<tr><td><input type="text" id="fore" size="30px" onkeyup="foring(this.value)" onfocus="this.value=''" value="Enter color name . . ." onBlur="getTip(this)"/></td></tr>
<tr><td>Background</td></tr>
<tr><td><input type="text" id="back" size="30px" onkeyup="backing(this.value)" onfocus="this.value=''" value="Enter color name . . ." onblur="getTip(this)" /></td></tr>
</table>
<p>Tips:
<br/>
> Use Tab for moving the cursor to the next box.<br/>
> Use Shift+Tab for moving the cursor to the previus box.<br/>
> Enter color name like blue or enter hex color rgb code like #f0f, #ff00ff
</p>
</div>
 
<style>
#page { -moz-box-shadow: 0 0 4px #aaa; padding: 10px; -moz-border-radius: 4px; }
#satu { -moz-border-radius: 4px; -moz-box-shadow: 0 0 4px #aaa; padding: 10px; width: 500px; height: 30px; margin: 0 auto; text-align: center; font: 12px sans-serif; background: pearl; font-weight: bold;  }
table td { font: 12px arial; }
input { -moz-box-shadow: 0 0 4px #ccc; -moz-border-radius: 4px; border: 1px solid #ccc; padding: 2px; font: 12px arial; }
input:hover { -moz-box-shadow: 0 0 4px orange; }
input:focus { -moz-box-shadow: 0 0 4px #ccc; }
p { font: 12px sans-serif; color: #444; background: ivory;  -moz-border-radius: 4px; padding: 10px; -moz-box-shadow: 0 0 4px #aaa; }

</style>

<script>
function foring(color){
 document.getElementById('satu').style.color = color;
}

function backing(color){
  document.getElementById('satu').style.backgroundColor = color;

}

function getTip(id){
 if(id.value.length==0){
  id.value = 'Enter color name . . .';
 }
}
</script>

Web App - Coloring V1

/**
 * This program will check in real time what looks like the color
 * you enter to affect foreground and background. Just copy this
 * code in http://htmledit.squarefree.com
 *
 * @name    : real time checker for color
 * @author  : irfanudin ridho
 * @email   : irfan.ub@gmail.com
 * @version : 1.0
 * @date    : March 1, 2011
 */


<div id="page">
    <div id="satu">For the last moment we get from here</div>
    <table>
        <tr>
            <td>Foreground</td>
        </tr>
        <tr>
            <td><input type="text" id="fore" size="30px"
                onkeyup="foring(this.value)"/></td>
        </tr>
        <tr>
            <td>Background</td>
        </tr>
        <tr>
            <td><input type="text" id="back" size="30px"
                onkeyup="backing(this.value)"/></td>
        </tr>
    </table>
</div>

<style>
#page { -moz-box-shadow: 0 0 4px #aaa; padding: 10px; -moz-border-radius: 4px; }
#satu { -moz-border-radius: 4px; -moz-box-shadow: 0 0 4px #aaa; padding: 10px; width: 500px; height: 30px; margin: 0 auto; text-align: center; font: 12px sans-serif; background: pearl; font-weight: bold;  }
table td { font: 12px arial; }
input { -moz-box-shadow: 0 0 4px #ccc; -moz-border-radius: 4px; border: 1px solid #ccc; padding: 2px; font: 12px arial; }
input:hover { -moz-box-shadow: 0 0 4px orange; }
input:focus { -moz-box-shadow: 0 0 4px #ccc; }
</style>

<script>
function foring(color){
    document.getElementById('satu').style.color = color;
}

function backing(color){
    document.getElementById('satu').style.backgroundColor = color;
}
</script>

OpenGL - Coordinate System

/**
 * This program will draw coordinate system line
 * x line and y line with their corresponding strips
 */
 
#include <GL/gl.h>
#include <GL/glu.h>
#include <GL/glut.h>

#define LIMIT 20.0      // limit
#define CENTER (LIMIT - LIMIT - 1)


// prototype
void setup();   // initialization of the program
void display(); // drawing method
void createCoordinate();  // certasian coordinate
void draw();    // draw the object

void createCoordinate(){
    glColor3f(1.0, 0.0, 0.0);
    glBegin(GL_LINES);
        // horizontal lines
        glVertex2f(-LIMIT, 0.0);
        glVertex2f(LIMIT, 0.0);

        // vertical lines
        glVertex2f(0.0, -LIMIT);
        glVertex2f(0.0, LIMIT);
    glEnd();

    // creating strips
    int i=0;
    for(i=0;i<20;i++){
    glColor3f(0.1, 0.0, 1.0);
    glBegin(GL_LINES);
        // horizontal strips
        glVertex2f(i, 0.10);
        glVertex2f(i, -0.10);

        // vertical strips
        glVertex2f(0.10, i);
        glVertex2f(-0.10, i);
    glEnd();
    }
}

// initialization setting
void setup(){
    glClearColor(1.0, 1.0, 1.0, 1.0);
    gluOrtho2D(CENTER, LIMIT, CENTER, LIMIT); // -x1, x2, -y1, y2
}

void display(){
    glClear(GL_COLOR_BUFFER_BIT);
    glColor3f(1.0, 0.0, 0.0);


    createCoordinate();
    draw();


    glFlush();
}

// drawing area
void draw(){
    // your code here
}


int main(int argc, char *argv[]){
    glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
    glutInitWindowPosition(200, 100);
    glutInitWindowSize(400, 300);
    glutCreateWindow("Hello World");
    glutDisplayFunc(display);

    setup();
    glutMainLoop();


    return 0;

}

OpenGL - Histogram

#include <GL/gl.h>
#include <GL/glu.h>
#include <GL/glut.h>

#include <iostream>
using namespace std;

#define LIMIT 20.0      // limit
#define CENTER (LIMIT - LIMIT - 1)


// prototype
void setup();   // initialization of the program
void display(); // drawing method
void createCoordinate();  // certasian coordinate
void draw();    // draw the object
void createBox(float, float, float, float);

void setup(){
    glClearColor(1.0, 1.0, 1.0, 1.0);
    gluOrtho2D(CENTER, LIMIT, CENTER, LIMIT); // -x1, x2, -y1, y2
}

void display(){
    glClear(GL_COLOR_BUFFER_BIT);
    glColor3f(1.0, 0.0, 0.0);

    draw();
    createCoordinate();

    glFlush();
}


void draw(){

    createBox(1.0, 1.0, 2.0, 10.0);
    createBox(4.0, 1.0, 2.0, 15.0);
    createBox(7.0, 1.0, 2.0, 13.0);
    createBox(10.0, 1.0, 2.0, 9.0);
    createBox(13.0, 1.0, 2.0, 7.0);
    createBox(16.0, 1.0, 2.0, 10.0);
   
}

void createBox(float x, float y, float width, float height){
    glBegin(GL_POLYGON);
        glVertex2f(x, y);
        glVertex2f(x, y+height);
        glVertex2f(x+width, y+height);
        glVertex2f(x+width, y);
    glEnd();
}

void createCoordinate(){
    glBegin(GL_LINES);
        // horizontal lines
        glVertex2f(-LIMIT, 0.0);
        glVertex2f(LIMIT, 0.0);

        // vertical lines
        glVertex2f(0.0, -LIMIT);
        glVertex2f(0.0, LIMIT);
    glEnd();
}

int main(int argc, char *argv[]){
    glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
    glutInitWindowPosition(200, 100);
    glutInitWindowSize(400, 300);
    glutCreateWindow("Hello World");
    glutDisplayFunc(display);

    setup();
    glutMainLoop();



    return 0;

}

Friday, February 25, 2011

Drupal Module - User View V1

<?php
/**
 * This module provide as viewer for drupal user in a block
 *
 * @type     : drupal module - block, db
 * @author   : irfanudin ridho
 * @email    : irfan.ub@gmail.com
 * @version  : 1.0
 * @date     : February 26, 2011
 */
 
/**
 * Implements hook_block_info()
 */
function user_view_block_info(){
    $block['view_user'] = array(
        'info' => t('User View'),
        'cache' => DRUPAL_CACHE_PER_ROLE,
        'region' => 'sidebar_first',
        'visibility' => 1,
        'pages' => '*',
        'status' => NULL,
    );
   
    return $block;
}

Drupal Module - Dosen Mata Kuliah

<?php

/**
 * This module show how to impelements JOIN operation. 
 * There's two table
 * Table dmk_dosen:
 *         id int not null auto_increment key,
 *        dosen char(50)
 * Table dmk_mata_kuliah:
 *        id int not null auto_increment key,
 *         mata_kuliah char(20)
 *
 * @type     : drupal module - db, menu
 * @author   : irfanudin ridho
 * @email    : irfan.ub@gmail.com
 * @version  : 1.0
 * @date     : February 25, 2011
 */
 
/**
 * Implements hook_menu()
 */
function dosen_matkul_menu(){
    $items = array();
    $items['dosen'] = array(
        'title' => 'Dosen Mata Kuliah',
        'page callback' => 'get_dosen_matkul',
        'access callback' => TRUE,
    );
   
    return $items;
}


/**
 * render the dosen and mata kuliah data to table
 */
function get_dosen_matkul(){
    $output = '';
   
    $dosen = db_select('dmk_dosen')->fields('dmk_dosen')
            ->execute()->fetchAll();
    $matkul = db_select('dmk_mata_kuliah','mk')->fields('mk')
            ->execute()->fetchAll();
   
    $output .= '<div>';
   
    // table of dosen
    $output .= '<div><h2>Daftar Dosen</h2>';
    $output .= '<table><tr><th>No</th><th>Dosen</th></tr>';
   
    $i = 1;
    foreach($dosen as $key){
        $output .= '<tr>';
        $output .= '<td>'.$i++.'</td>';
        $output .= '<td>'.$key->dosen.'</td>';
        $output .= '</tr>';
    }
    $output .= '</table></div>';
   
    // table of mata kuliah
    $output .= '<div><h2>Daftar Mata Kuliah</h2>';
    $output .= '<table><tr><th>No</th><th>Mata Kuliah</th></tr>';
   
    $j = 1;
    foreach($matkul as $key){
        $output .= '<tr>';
        $output .= '<td>'.$j++.'</td>';
        $output .= '<td>'.$key->mata_kuliah.'</td>';
        $output .= '</tr>';
    }
    $output .= '</table></div>';
   
    $output .= '</div>';
   
    return $output;
}