Categorized
Export Spotify Playlist with Excel 2007 to XML
4Step 1. Drag and Drop your playlist into Excel.
Step 2. Extract the track data (artist and track) by using the “Text to Columns” feature in the data section of the ribbon.
Step 3. Extract the url by using the custom excel function mentioned below (Google if you don’t know how to add it to an Excel worksheet or use example file playlist.xlsm).
Step 4. Add the XML mapping (playlist.xsd or create the file by using the code below) by using the XML Source option of the developer section of the ribbon. Again Google if you don’t know how to enable the developer section and/or add a XML mapping to an Excel file.
Step 5. Match the columns with the items of the mapping.
Step 6. Export the file to xml …
Excel playlist.xslm
XML Schema Mapping playlist.xsd
Example of the exported XML playlist.xml
XML Schema Mapping
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:complexType name="spotifyitem">
<xs:sequence>
<xs:element name="track"/>
<xs:element name="artist"/>
<xs:element name="httplink"/>
</xs:sequence>
</xs:complexType>
<xs:element name="playlist">
<xs:complexType>
<xs:sequence>
<xs:element name="item" type="spotifyitem" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
Visual Basic Code to extract the URL.
Function LinkAddress(cell As Range, _
Optional default_value As Variant)
'Lists the Hyperlink Address for a Given Cell
'If cell does not contain a hyperlink, return default_value
If (cell.Range("A1").Hyperlinks.Count <> 1) Then
LinkAddress = default_value
Else
LinkAddress = cell.Range("A1").Hyperlinks(1).Address
End If
End Function
Calculating the Difference in Days Between Two Zend_Date Objects (Revised …)
0Calculate the amount of calendar days between two dates …
// Test cases ...
$startdate = new Zend_Date('15-05-2010','dd-MM-yyyy'); $enddate = new Zend_Date('10-11-2010','dd-MM-yyyy');
// $startdate = new Zend_Date('02-01-2010','dd-MM-yyyy'); $enddate = new Zend_Date('15-05-2010','dd-MM-yyyy');
// $startdate = new Zend_Date('15-05-2010','dd-MM-yyyy'); $enddate = new Zend_Date('15-05-2015','dd-MM-yyyy');
// $startdate = new Zend_Date('10-11-2010','dd-MM-yyyy'); $enddate = new Zend_Date('15-05-2010','dd-MM-yyyy');
$newdate = clone $enddate;
// Correction for DST
$dts = $startdate->getGmtOffset() - $enddate->getGmtOffset();
$newdate->sub($startdate);
$days = ($newdate->getTimestamp() + $dts) / (60 * 60 * 24) ;
var_dump($days);
// Really disliked this solution that I came across (hence it's slow ...)
// http://cmorrell.com/webdev/calculating-the-difference-in-days-between-two-zend_date-objects-373
$n_days = 0;
for ( $i = clone $startdate ; $i->isEarlier( $enddate ) ; $i->add( '01', Zend_Date::DAY ) ) {
$n_days++;
};
var_dump($n_days);
// Alternative, prevent DST by setting the timezone to GMT
$startdate = new Zend_Date();
$enddate = new Zend_Date();
$startdate->setTimezone('GMT');
$enddate->setTimezone('GMT');
$startdate->setDate('15-05-2010','dd-MM-yyyy');
$enddate->setDate('10-11-2010','dd-MM-yyyy');
$enddate->sub($startdate);
$days = $enddate->getTimestamp() / (60 * 60 * 24) ;
var_dump($days);
Remarks:
- Using YYYY instead of yyyy will mess up the Zend_Date->add() function.
To elaborate – YYYY is incorrect in this case. You’re assuming that
Zend_Date uses PHP’s format by default but it does not. It uses the
ISO format by default. (source link)
Prepend this to your code:
Zend_Date::setOptions(array('format_type' => 'php'));
- Also use “dd” instead of “DD” (day of the year), I guess I’ve got a preference for uppercasing.
Use Zend_Log_Writer_Db with Oracle
0My apologies for the quick and dirty implementation, it’s just a working proof of concept!
1. Create a table like
CREATE TABLE "APP_LOG" (
"LOGID" CHAR(36),
"TIMESTAMP" VARCHAR2(100),
"PRIORITY" VARCHAR2(100),
"PRIORITYNAME" VARCHAR2(100),
"MESSAGE" VARCHAR2(1000),
"XMLDATA" "XMLTYPE",
"DATA" CLOB,
"APPNAME" VARCHAR2(100),
"APPVERSION" VARCHAR2(100),
CONSTRAINT "PK_APP_LOG" PRIMARY KEY ("LOGID")
)
Use the following code to test logging with Zend_Log_Writer_Db, this will fail …
$log = new Zend_Log();
$log->setEventItem('appversion','1.0');
/* @var $db Zend_Db_Adapter_Oracle */
$db = Zend_Registry::get('testdb');
$dbwriter = new Zend_Log_Writer_Db($db,'APP_LOG');
$log->addWriter($dbwriter);
$xml = new SimpleXMLElement ( '<document/>' );
$xml->addChild ( 'version', '1.0' );
$xml->addChild ( 'timestamp', $this->timestamp );
$xml->addChild ( 'action', 'TEST' );
$id = uniqid();
$log->log('test',Zend_Log::DEBUG,array('logid'=>$id,'xmldata'=>$xml->asXML()) );
Oracle enjoys upper-cased field names and the standard Zend_Log_Writer_Db does not provide upper-cased field names.
To fix this:
1. Extend or re-implement Zend_Log_Writer_Db and implement the following write function:
protected function _write($event)
{
if ($this->_db === null) {
require_once 'Zend/Log/Exception.php';
throw new Zend_Log_Exception('Database adapter is null');
}
if ($this->_columnMap === null) {
$dataToInsert = array();
foreach ($event as $key => $value) {
$dataToInsert[strtoupper($key)] = $value;
}
} else {
$dataToInsert = array();
foreach ($this->_columnMap as $columnName => $fieldKey) {
$dataToInsert[strtoupper($columnName)] = $event[$fieldKey];
}
}
$this->_db->insert($this->_table, $dataToInsert);
}
2. Or enable case-folding on the Oracle adapter by changing “Oracle.php” line 621
$cols[] = $this->quoteIdentifier($col, true);
into
$cols[] = $this->quoteIdentifier($this->foldCase($col), true);
and enable case-folding by configuration like for example
resources.multidb.db1.options.caseFolding = 1
See also: ZF-10478
To support the timestamp with timezone:
// "TIMESTAMP" TIMESTAMP WITH TIME ZONE
if (isset($dataToInsert['TIMESTAMP'])) {
$dataToInsert['TIMESTAMP'] =
new Zend_Db_Expr("to_timestamp_tz('".$dataToInsert['TIMESTAMP']."','YYYY-MM-DD\"T\"HH24:MI:SS TZH:TZM')");
}
ROFLMOA of the Day from the Retro-styled Game Dwarf Fortress
0Play Dwarf Fortress.
ARMOK DEMANDS WEEKLY PROGRESS REPORTS, LEST HE FORCE YOU TO BUILD HIS MACHINATIONS WITH THE BONES OF YOUR CHILDREN! ARMOK ALSO DEMANDS A COVER SHEET!
from Reddit
A CSS Sprites Helper Tool (written in jQuery)
0CSS Sprites are the preferred method for reducing the number of image requests. Combine your background images into a single image and use the CSS background-image and background-position properties to display the desired image segment.
References:
Best Practices for Speeding Up Your Web Site
CSS Sprites: Image Slicing’s Kiss of Death
Sourcecode (bitbucket repository)
The Helper is part of a little gaming project of mine. The interface, although bare-bone, is working fine.
1. Add the url of the image and provide the icon dimensions.
2. Press “load” (try loading a second time if the image is shown too small, little bug to fix soon).
3. Use the prefix and name field for the CSS class name.
4. Click an icon.
5. Repeat step 3 and 4 to add CSS to the text-area.
6. Copy the CSS to your own file and read the reference for further instructions … a demo of an CSS Sprites implementation can also be found here: CSS Sprite Demo
CSS Sprites Helper Tool
Adding multiple databases to the Application.ini in Zend Framework
2application.ini
resources.multidb.db1.adapter = "mysqli" resources.multidb.db1.isDefaultTableAdapter = true resources.multidb.db1.host = "localhost" resources.multidb.db1.username = "xx" resources.multidb.db1.password = "xx" resources.multidb.db1.dbname = "zftutorial" resources.multidb.db2.adapter = "mysqli" resources.multidb.db2.isDefaultTableAdapter = false resources.multidb.db2.host = "localhost" resources.multidb.db2.username = "xx" resources.multidb.db2.password = "xx" resources.multidb.db2.dbname = "bboard"
bootstrap.php
protected function _initDatabase ()
{
$resource = $this->getPluginResource('multidb');
$resource->init();
Zend_Registry::set('db1', $resource->getDb('db1'));
Zend_Registry::set('db2', $resource->getDb('db2'));
}
Use by calling:
$db = Zend_Registry::get('db1');
$result = $db->fetchAll ( "select * from mytable", array ());
Reporting Live Status of Livestreams with PHP & jQuery
4DEMO
References:
- Livestream Channel API 2.0
- Zend_Json
- jQuery Ajax
- Livestream
islive.php
<?php
/*
ini_set('display_errors', 1);
error_reporting(E_ALL);
*/
/*
* http://framework.zend.com/manual/en/zend.json.html
*/
include_once 'Json.php';
header('Cache-Control: no-cache, must-revalidate');
header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
header('Content-type: application/json');
try {
$url = '';
switch ($_GET['name']) {
case 'cowclan':
$url = 'http://xcowclanx.channel-api.livestream-api.com/2.0/livestatus';
break;
case 'rebootgpf':
$url = 'http://xrebootgpfx.channel-api.livestream-api.com/2.0/livestatus';
break;
case 'clgaming':
$url = 'http://xclgamex.channel-api.livestream-api.com/2.0/livestatus';
break;
}
function isLive($url) {
$data = file_get_contents($url);
$xml = new SimpleXMLElement($data);
$nsdata = $xml->children('http://api.channel.livestream.com/2.0');
$list = array();
foreach($nsdata as $c) {
$list[$c->getName()] = (string)$c;
}
return $_GET['callback'].'('.Zend_Json::encode($list).')';
}
if (!empty($url)) {
echo isLive($url);
} else {
echo $_GET['callback'].'('.Zend_Json::encode(array('error'=>'404')).')';
}
} catch (Exception $e) {
echo $_GET['callback'].'('.Zend_Json::encode(array('error'=>'503')).')';
}
$err = error_get_last();
if (!empty($err)) {
echo $_GET['callback'].'('.Zend_Json::encode(array('error'=>'500')).')';
}
?>
Code Snippet from the DEMO
function updateStreamInfo(channel, element, name) {
$.ajax({
url : "http://ingol.nl/lol/livestream/islive.php?name="+channel,
type : "GET",
dataType : "jsonp",
success : function(data, textStatus, XMLHttpRequest){
var color = {'color':'#FFFFFF'};
if (data.isLive && data.isLive == 'true') {
color = {'color':'#FF0000'};
} else {
color = {'color':'#FFFFFF'};
}
var viewercount = 'undefined' === typeof(data.currentViewerCount) ? '-.-' : data.currentViewerCount;
var link = $('<a/>').attr({'href':'http://livestream.com/'+channel,"target":"livestream"}).css(color)
.html('LIVESTREAM '+name.toUpperCase()+' ('+viewercount+')');
element.html(link);
},
error : function(XMLHttpRequest, textStatus, errorThrown){
// console.debug(XMLHttpRequest);
}
});
}
function isLiveStatus(name,channel) {
var minutes = 5;
updateStreamInfo(channel,$('#'+name), name);
window.setInterval('updateStreamInfo("'+channel+'",$("#'+name+'"), "'+name+'")', 1000 * 60 * minutes);
}
$(function(){
isLiveStatus('rebootgpf','rebootgpf');
isLiveStatus('clgaming','clgame');
isLiveStatus('cowclan','cowclan');
isLiveStatus('Team-AON','teamaon');
$('#popup').click(function(){
window.open('index.html','livestreams','width=400,height=200,menubar=no,status=no,location=no,toolbar=no,scrollbars=no');
});
});
