Tag Archive for iteration

list->mysql query iteration for cron job

$x = ceil( substr( date( "i" ), 1, 1) / 2 );	//get number from 1 to 5
$min = ( 20 * ( $x - 1 ) ) + 1;	//gets 1, 21, 41, 61, 81
$max = ( 20 * $x ); 	//gets 20, 40, 60, 80, 100

$feedListSql = quotesmart( "SELECT DISTINCT id, feed_url FROM {$this->feedTable} WHERE active = 1 AND id >= {$min} AND id <= {$max}" );

source

Detect the first and last iteration of a loop in Ruby

- @random_pubs[0..3].each_with_index do |pub, count|
%li{:class => (count > 0 ? (count == 3 ? 'last' : '') : 'first')}
.description= pub.desc

source

Iterate Map – Dump Map

Iterator it = mp.entrySet().iterator();
while (it.hasNext()) {
Map.Entry pairs = (Map.Entry)it.next();
System.out.println(pairs.getKey() + " = " + pairs.getValue());

source

API deprecation

function deprecate(o,name,instead)
local msg = "%sWarning, deprecated feature "..(name and ("'"..name.."' ") or "").."in use."..(instead and ("  Use '"..instead.."' instead.") or "")
if(type(o) == "table") then
return setmetatable({},{__index = function (t,k)
local _,callpoint = pcall(function() error("",4) end)
print(string.format(msg,string.gsub(callpoint,"(^w%*%.%w*%:%d+)","%1")))
return o[k]
end,
__newindex = function (t,k,v)
local _,callpoint = pcall(function() error("",4) end)
print(string.format(msg,string.gsub(callpoint,"(^w%*%.%w*%:%d+)","%1")))
o[k] = v
return o[k]
end
})
elseif(type(o) == "function") then
return function(...)
local _,callpoint = pcall(function() error("",4) end)
print(string.format(msg,string.gsub(callpoint,"(^w%*%.%w*%:%d+)","%1")))
return o(unpack(arg))
end
end
end
Ace = {}

function Ace:print(msg)
print(msg)
end

function foo()
print("FOO!")
end
ace = deprecate(Ace,"ace","Ace")
FOO = deprecate(foo,"FOO","foo")

FOO()
ace:print("moo")

./deprecate.lua:38: Warning, deprecated feature 'FOO' in use.  Use 'foo' instead.
FOO!
./deprecate.lua:39: Warning, deprecated feature 'ace' in use.  Use 'Ace' instead.
moo

source

Iterative Node Deletion

function killsChildNodes(an_element) {
while (an_element.hasChildNodes()) {
if (!an_element.firstChild.hasChildNodes()) {
var k = an_element.firstChild;
an_element.removeChild(k);
} else {
killsChildNodes2(an_element.firstChild);
}
}
}
function killsChildNodes2(another_element) {
while (another_element.hasChildNodes()) {
if (!another_element.firstChild.hasChildNodes()) {
var k2 = another_element.firstChild;
another_element.removeChild(k2);
} else {
killsChildNodes(another_element.firstChild);
}
}
}
function killAllChildNodesFrom(bob) {
if(document.getElementById(bob).hasChildNodes()) {
killsChildNodes(document.getElementById(bob));
}
}
function killFirstChildNodeFrom(bob) {
if(document.getElementById(bob).hasChildNodes()) {
killsChildNodes(document.getElementById(bob).firstChild);
document.getElementById(bob).removeChild(document.getElementById(bob).firstChild);
}
}
function killLastChildNodeFrom(bob) {
if(document.getElementById(bob).hasChildNodes()) {
killsChildNodes(document.getElementById(bob).lastChild);
document.getElementById(bob).removeChild(document.getElementById(bob).lastChild);
}
}

source