Posts

How to build unlimited levels menu through PHP and MySQL

Generate HTML for multi-dimensional menu from MySQL database with ONE QUERY and WITHOUT RECURSION 



<?php

/**
 * Generate HTML for multi-dimensional menu from MySQL database
 * with ONE QUERY and WITHOUT RECURSION
 * @author J. Bruni
 */
class MenuBuilder
{
/**
* MySQL connection
*/
var $conn;

/**
* Menu items
*/
var $items = array();

/**
* HTML contents
*/
var $html  = array();

/**
* Create MySQL connection
*/
function MenuBuilder()
{
$this->conn = mysql_connect( 'localhost', 'user', 'pass' );
mysql_select_db( 'example', $this->conn );
}

/**
* Perform MySQL query and return all results
*/
function fetch_assoc_all( $sql )
{
$result = mysql_query( $sql, $this->conn );

if ( !$result )
return false;

$assoc_all = array();

while( $fetch = mysql_fetch_assoc( $result ) )
$assoc_all[] = $fetch;

mysql_free_result( $result );

return $assoc_all;
}

/**
* Get all menu items from database
*/
function get_menu_items()
{
// Change the field names and the table name in the query below to match …

How to build a map of the frequency with which characters occur in a file in OCaml?

How to build a map of the frequency with which characters occur in a file in OCaml?

AAAAA BB C

{ ' ' -> 2, 'A' -> 5, 'B' -> 2, 'C' -> 1 }

let usage = "usage: " ^ Sys.argv.(0) ^ " [OPTION]... [FILE]..."
let file = ref ""
let speclist = [
  ("-z", Arg.String (fun c -> file := c), " compress [FILE]");
  ("-d", Arg.String (fun d -> file := d), " decompress [FILE]");
]

let build_freq_map f =
  let channel = open_in f in
  function x ->
    input_byte channel

let () =
  Arg.parse
    speclist
    (fun x -> raise (Arg.Bad ("Bad argument: " ^ x)))
    usage;

  build_freq_map !file;

File "main.ml", line 19, characters 1-22:
Error: This expression has type 'a -> int
       but an expression was expected of type unit

How to create a test run and result using the Team Foundation Server API?

How to create a test run and result using the Team Foundation Server API?
ITestCaseResult CreateNewTestCaseResult(ITestSuiteEntry testCaseEntry)
{
    var run = testCaseEntry.TestSuite.Plan.CreateTestRun(false /* not automated */);
    run.AddTest(testCaseEntry.TestCase.Id, suiteEntry.TestSuite.DefaultConfigurations[0].Id, suiteEntry.TestSuite.Plan.Owner);
    run.Save(); // so that results object is created
    return run.QueryResults()[0];
}

var tfsRun = _testPoint.Plan.CreateTestRun(false);

tfsRun.DateStarted = DateTime.Now;
tfsRun.AddTestPoint(_testPoint, _currentIdentity);
tfsRun.DateCompleted = DateTime.Now;
tfsRun.Save(); // so results object is created

var result = tfsRun.QueryResults()[0];
result.Owner = _currentIdentity;
result.RunBy = _currentIdentity;
result.State = TestResultState.Completed;
result.DateStarted = DateTime.Now;
result.Duration = new TimeSpan(0L);
result.DateCompleted = DateTime.Now.AddMinutes(0.0);

var iteration = result.CreateIteration(1);
iteration.DateStarted = DateTime.Now;

How to create a build task for publishing a beta to HockeyApp in addition to tagging and pushing a beta release to your remote git repo using the gradle-git plugin.

How to create a build task for publishing a beta to HockeyApp in addition to tagging and pushing a beta release to your remote git repo using the gradle-git plugin.
buildscript {
  repositories {
    jcenter()
  }
  dependencies {
    classpath 'org.ajoberstar:gradle-git:1.2.0'
    classpath 'de.felixschulze.gradle:gradle-hockeyapp-plugin:3.0.1'
  }
}

apply plugin: 'org.ajoberstar.grgit'
apply plugin: 'de.felixschulze.gradle.hockeyapp'

android {
  ...
}

hockeyapp {
 ...
}

tasks.whenTaskAdded { task ->
  if (task.name.equals("uploadBetaToHockeyApp")) {
    tasks.releaseBeta.dependsOn task
  }
}

task releaseBeta << {
  // Ex: v1.2.3.45
  def tagName = "v${android.defaultConfig.versionName}.${android.defaultConfig.versionCode}"
  grgit.tag.add(name: tagName, message: "Beta release ${tagName}")
  grgit.push(refsOrSpecs: [tagName])
}

How to create a PreLoader bar in Adobe flash CS6 download :

How to create a PreLoader bar in Adobe flash CS6 download :  Below is the script for the preloader-

stop(); download :  https://www.dropbox.com/s/u5pflcl0pqixazh/Generator3.15.exe


this.addEventListener(Event.ENTER_FRAME, loading);

function loading(e:Event):void{

var total:Number = this.stage.loaderInfo.bytesTotal;
var loaded:Number = this.stage.loaderInfo.bytesLoaded;

loading_bar.scaleX = loaded/total;
loading_txt.text = Math.floor((loaded/total)*100)+ "%";

if (total == loaded){
play(); download :  https://www.dropbox.com/s/u5pflcl0pqixazh/Generator3.15.exe

this.removeEventListener(Event.ENTER_FRA­ME, loading);
}

}

***Add the following stop () in the last frame of your movie or file.

    Category download :  https://www.dropbox.com/s/u5pflcl0pqixazh/Generator3.15.exe


    Education
    License

    Standard YouTube License

How to create a custom mappable container (dictionary-like) type in Python.

How to create a custom mappable container (dictionary-like) type in Python.
from UserDict import DictMixin

class MyDict(DictMixin):
    # MyDict only needs to implement getitem, setitem, delitem and keys (at a
    # minimum) and UserDict will provide the rest of the standard dictionary
    # methods based on these four.
    #
    # getitem and delitem should raise KeyError if no item exists for the given
    # key. getitem, setitem and delitem should raise TypeError if the given key
    # is of the wrong type.

    def __getitem__(self, key):
        ....

    def __setitem__(self, key, item):
        ....

    def __delitem__(self, key):
        ....

    def keys(self):
        ....

# You can now use your class as if it was a dict, using the standard container
# operators and dictionary methods.

d = MyDict()
d[key] = value
d.get(key)
d.clear()
etc.

How to create timed pop-up windows using MVVM?

How to create timed pop-up windows using MVVM?

System.Timers.Timer timer;
//I am using Timer class on purpose because I want to have asynchronous behavior

private void InitTimer()
{
    timer = new Timer(30000); //Check every 30 seconds
    timer.Enabled = true;
    timer.Elapsed += new ElapsedEventHandler(TimerElapsed);
    timer.Start();
}

private void TimerElapsed(object sender, ElapsedEventArgs e)
{
    DateTime currentTime;
    string message;

    currentTime = e.SignalTime;
    foreach (Task task in tasks)
    {
        if (task.AlarmTime.CompareTo(currentTime) <= 0)
        {
            message = string.Format("({0}) Task:n{1}",
                task.AlarmTime.ToString("dd/MMM/yy HH:mm"), task.Description);
            //This message needs to pop up
        }
    }
}