public static DataTable ConvertXmlNodeListToDataTable(XmlNodeList xnl)
{
DataTable dt = new DataTable();
int TempColumn = 0;
foreach (XmlNode node in xnl.Item(0).ChildNodes)
{
TempColumn++;
DataColumn dc = new DataColumn(node.Name, System.Type.GetType("System.String"));
if (dt.Columns.Contains(node.Name))
{
dt.Columns.Add(dc.ColumnName = dc.ColumnName + TempColumn.ToString());
}
else
{
dt.Columns.Add(dc);
}
}
int ColumnsCount = dt.Columns.Count;
for (int i = 0; i < xnl.Count; i++)
{
DataRow dr = dt.NewRow();
for (int j = 0; j < ColumnsCount; j++)
{
dr[j] = xnl.Item(i).ChildNodes[j].InnerText;
}
dt.Rows.Add(dr);
}
return dt;
}
Tag Archive for list
snippets |
February 3, 2012
Convert XmlNodeList To DataTable
snippets |
January 13, 2012
Block Lists
/* -- blocklists --*/
ul.blockList {
list-style-type: none;
margin: 20px 0;
}
ul.blockList li {
margin-bottom: 20px
}
ul.blockList li h3,
ul.blockList li p.meta {
display: inline;
margin: 0;
padding: 0;
}
ul.blockList li p.meta {
font-size: 0.8em;
margin-left: 1em;
margin-top: 0;
}
ul.blockList li blockquote {
border: none;
margin: 0.5em 0 0 0;
padding-left: 0;
font-style: normal;
}
snippets |
January 8, 2012
List of Events from CiviCRM
<?php
function cmp_date($a,$b) {
if ($a['start_date'] > $b['start_date']) return 1;
if ($a['start_date'] < $b['start_date']) return -1;
return 0;
}
if (module_exists('civicrm')) {
civicrm_initialize(TRUE);
require_once 'api/v2/Event.php';
$params = array ();
$myEvents = civicrm_event_search( $params );
if ($myEvents) {
$count = 0;
$last = '';
usort($myEvents,'cmp_date');
foreach ($myEvents as $event) {
$now = date('Y-m-d H:i:s');
if ($now > $event['start_date']) continue;
$startdate = date('D M j Y',strtotime($event['start_date']));
$enddate = date('D M j Y',strtotime($event['end_date']));
$eventid = $event['id'];
list($title_place, $title_desc) = split(":",$event['title'],2);
if ($last != $startdate) {
$display = '<br /><b>'.$startdate.'</b><br />';
}
$display .= l($title_place.' '.$title_desc, 'civicrm/event/info', array(), 'reset=1&id='.$event['id']).'<br />';
echo $display;
$count++;
$last = $startdate;
if ($count > <img src='http://www.snippetsmania.com/wp-includes/images/smilies/icon_cool.gif' alt='8)' class='wp-smiley' /> break;
// this limits the number of events to 8 - put in whatever number suits you
}
if ($count > 0) {
} else {
echo 'No events found.';
}
} else {
echo 'No events found.';
}
}
?>
snippets |
January 8, 2012
List of Events from CiviCRM
<?php
function cmp_date($a,$b) {
if ($a['start_date'] > $b['start_date']) return 1;
if ($a['start_date'] < $b['start_date']) return -1;
return 0;
}
if (module_exists('civicrm')) {
civicrm_initialize(TRUE);
require_once 'api/v2/Event.php';
$params = array ();
$myEvents = civicrm_event_search( $params );
if ($myEvents) {
$count = 0;
$last = '';
usort($myEvents,'cmp_date');
foreach ($myEvents as $event) {
$now = date('Y-m-d H:i:s');
if ($now > $event['start_date']) continue;
$startdate = date('D M j Y',strtotime($event['start_date']));
$enddate = date('D M j Y',strtotime($event['end_date']));
$eventid = $event['id'];
list($title_place, $title_desc) = split(":",$event['title'],2);
if ($last != $startdate) {
$display = '<br /><b>'.$startdate.'</b><br />';
}
$display .= l($title_place.' '.$title_desc, 'civicrm/event/info', array(), 'reset=1&id='.$event['id']).'<br />';
echo $display;
$count++;
$last = $startdate;
if ($count > <img src='http://www.snippetsmania.com/wp-includes/images/smilies/icon_cool.gif' alt='8)' class='wp-smiley' /> break;
// this limits the number of events to 8 - put in whatever number suits you
}
if ($count > 0) {
} else {
echo 'No events found.';
}
} else {
echo 'No events found.';
}
}
?>
snippets |
January 6, 2012
Textpattern State List for Zem Contact (zem_contact_reborn)
<txp:zem_contact_select label="State" list="Alabama,Alaska,Arizona,Arkansas,California,Colorado,Connecticut,Delaware,District of Columbia,Florida,Georgia,Hawaii,Idaho,Illinois,Indiana,Iowa,Kansas,Kentucky,Louisiana,Maine,Maryland,Massachusetts,Michigan,Minnesota,Mississippi,Missouri,Montana,Nebraska,Nevada,New Hampshire,New Jersey,New Mexico,New York,North Carolina,North Dakota,Ohio,Oklahoma,Oregon,Pennsylvania,Rhode Island,South Carolina,South Dakota,Tennessee,Texas,Utah,Vermont,Virginia,Washington,West Virginia,Wisconsin,Wyoming" break="" />
snippets |
December 24, 2011
Remove duplicate lines from a text file with Perl
#!/usr/bin/perl -w
use strict;
my $origfile = shift;
my $outfile = "no_dupes_" . $origfile;
my %hTmp;
open (IN, "<$origfile") or die "Couldn't open input file: $!";
open (OUT, ">$outfile") or die "Couldn't open output file: $!";
while (my $sLine = <IN>) {
next if $sLine =~ m/^s*$/; #remove empty lines. Without this, still destroys empty lines except for the first one.
$sLine=~s/^s+//; #strip leading/trailing whitespace
$sLine=~s/s+$//;
print OUT qq{$sLine
} unless ($hTmp{$sLine}++);
}
close OUT;
close IN;
snippets |
December 15, 2011
comma separated placeholder
values = [1, 2, 3]
# => [1, 2, 3]
s = '?' * values.size
# => "???"
csv = s.split(//).join(',')
# => "?,?,?"
snippets |
December 9, 2011
Paginate with sort by
def list @page_title ='List books' # Good job! sort_by = params[:sort_by] @book_pages, @books = paginate :books, <img src='http://www.snippetsmania.com/wp-includes/images/smilies/icon_surprised.gif' alt=':o' class='wp-smiley' /> rder => sort_by, :per_page => 10 end
snippets |
November 28, 2011
Iteration through a Generic List (Java 5 version)
List<String> listOfStrings = new LinkedList<String>( );
listOfStrings.add("Why");
listOfStrings.add("Iterate");
listOfStrings.add("When");
listOfStrings.add("You");
listOfStrings.add("Can");
listOfStrings.add("Avoid");
listOfStrings.add("It!");
for (String s: listOfStrings) {
System.out.println(s);
}
snippets |
November 24, 2011
Get HTML list of Array Keys
/**
* Creates recursively a nested HTML UL of array keys.
* @param array $array Array
* @return string Nested UL string
*/
function Get_Array_Keys_UL($array=array()) {
$recursion=__FUNCTION__;
if (empty($array)) return '';
$out='<ul>'."
";
foreach ($array as $key => $elem)
$out .= '<li>'.$key.$recursion($elem).'</li>'."
";
$out .= '</ul>'."
";
return $out;
}
$ul=Get_Array_Keys_UL($_POST);
echo $ul;