var list = new List<string>() { // Assume some items in the list };
for (var i = 0; i < list.Count; i++)
{
var item = list[i];
list.Remove(item);
i--;
}
Simple alternative to List.Clear()
double zuida(std::vector<double> vec) {
std::vector<double> temp;
for(int i = 0; i < vec.size(); i++)
temp.push_back(vec[i]);
notend:
if(temp.size() > 0) {
if(temp.size() < 2) {
double tmp = *(&temp[0]);
return tmp;
}
else if(temp.size() >= 2) {
double mini = temp[0];
int ind = 0;
for(int i = 0; i < temp.size(); i++)
if(temp[i] < mini) {
mini = temp[i];
ind = i;
}
temp.erase(temp.begin() + ind);
goto notend;
}
}
}
The beauty is that every case is the best (also worst) case!
public class MetricsChecker
{
protected const string AwaitingRecognitionCountMetricName = "AwaitingRecognitionCount";
protected const string AwaitingExportCountMetricName = "AwaitingExportCount";
protected const string NotYetDownloadedEventCountMetricName = "NotYetDownloadedEventCount";
...
public virtual void PublishNotYetDownloadedEventCounts()
{
this.logger.Trace($"Starting to gather and publish {NotYetDownloadedEventCountMetricName}(s).");
...
}
...
}
// What they did:
var serverCommands = {};
for(var each in commandList.general)
(dmCommands[commandList.general[each].type] ? dmCommands[commandList.general[each].type] +=
(config.prefix + each + (commandList.general[each].args ? ' ' + commandList.general[each].args : '') +
': ' + commandList.general[each].description + '\n') : (dmCommands[commandList.general[each].type] =
'\u200B'+ config.prefix + each + (commandList.general[each].args ? ' ' + commandList.general[each].args : '') +
': ' + commandList.general[each].description + '\n'))
// What they should've done:
let srvrCmds = new Map();
let gldCmds = commandList[message.guild.id];
for (let each in gldCmds) {
const cur = gldCmds[each];
const text = `${config.prefix + each + (cur.args ? " " + cur.args : "")}: ${cur.description}\n`;
const srvrCmdType = srvrCmds.get(cur.type);
srvrCmds.set(cur.type, (srvrCmdType || "\u200B") + text);
}
const rola = (usr: IUserData) => {
let student = "student"
let edukator = "edukator"
let dziekanat = "dziekanat"
let admin = "admin"
if(usr.type===1){
return student
}
else if(usr.type===2){
return edukator
}
else if(usr.type===3){
return dziekanat
}
else if(usr.type===4){
return admin
}
}
<table class="table table-sm o_main_table" style="width='100%'">
<!-- ... thanks ...-->
</table>
Found that on a customer's project, wonder if my employee knows about inline css
$MaxSizeGB = [math]::Round($MaxSize/1024/1024/1024,2)
Write-Output " the maximum size is $MaxSizeGB GB"
At least [math] is used. So close, and yet so far...
def dow_to_dict_from_self(self):
# res = {'name': self.name, 'enabled': self.enabled }
res = {'sun': 0, 'mon': 0, 'tue': 0, 'wed': 0, 'thr': 0, 'fri': 0,
'sat': 0,
'enabled': 0, 'dow': 0, 'name': 'untitled'}
if (int(self.days_of_week) & 0x01) == 0x01: # sun
res['sun'] = 1
if (int(self.days_of_week) & 0x02) == 0x02: # mon
res['mon'] = 1
if (int(self.days_of_week) & 0x04) == 0x04: # tue
res['tue'] = 1
if (int(self.days_of_week) & 0x08) == 0x08: # wed
res['wed'] = 1
if (int(self.days_of_week) & 0x10) == 0x10: # thr
res['thr'] = 1
res['thu'] = 1 # '%a' returns thu for Thursday
if (int(self.days_of_week) & 0x20) == 0x20: # fri
res['fri'] = 1
if (int(self.days_of_week) & 0x40) == 0x40: # sat
res['sat'] = 1
if (int(
self.days_of_week) & 0x40) == 0x80: # enabled # new enable#
# flag -- duplicate in db
res['enabled'] = 1
res['enabled'] = self.enabled # remove this
res['dow'] = self.days_of_week
res['name'] = self.name
return res
kept the original comments - they're very helpful
{!! Form::select('ticket_category', \App\Models\Term::whereHas('taxonomy', function($query) {
$query->where('slug', 'ticket_category');
})->whereIn('id', ['15', '16', '17', '18'])
->pluck('name','id'), old('ticket_category'), [
'id' => 'ticket_category',
'class' => 'form-control',
'placeholder' => 'Seleccione una categorÃa']
)
!!}
to do it in an array if you can put it in the database so that you still burn the position
if HOST == 'AdaLovelace' or HOST == 'vbu' or HOST == 'asus':
urlpatterns += patterns('',
(r'^site_media/(?P<path>.*)$', 'django.views.static.serve', {'document_root': MEDIA_ROOT}),
)
strcpy(szBuffer, sBuffer);
so many questions given you by Hungarian notation
private <T> Supplier<T> abort(Class<T> exception) {
return () -> {
try {
return exception.newInstance();
} catch (InstantiationException | IllegalAccessException e) {
throw new RuntimeException(e);
}
};
}
...
throw abort(MyException.class).get();
for (const order of orders) {
for (const resultItem of results) {
if (resultItem.machine != "TRANSFER") {
shiftsLoop: for (const shift of resultItem.shifts) {
if (shift.products) {
for (const product of shift.products) {
if (product.product == order.product) {
for (const routing of routings) {
if (routing.output == order.product) {
const machinePlant = findMachinePlant(resultItem.machine, machines)
if (routing.type == "ODP") {
if (machinePlant == order.plant) {
const msg = createMessage(order, shift, resultItem.machine, CHOR)
requests.push(buildRequest(msg))
} else {
//CHEE CHIE CHEI
}
break shiftsLoop
} else if (routing.type == "OCL" || routing.type == "RCL") {
const msg = createMessage(order, shift, resultItem.machine, CHCL)
requests.push(buildRequest(msg))
//CHCL
}
}
}
}
}
}
}
}
}
foreach($bookings as $booking) {
$status = $apiController->getBookingStatus($booking);
if($status->error == 1) {
switch($status->message) {
case "FIND_PRV_KO": continue; //Wrong parameters
case "ERR_PREN_NOTFOUND": continue; //Request booking cannot be found
case "ERR_PRV_NOTFOUND": continue; //Check-in not carried out
default: continue;
};
continue;
}
//DO SOME STUFF...
}
Found this on a production website
// powtierdzenie decyzji
function zapytaj(pytanie){
if(confirm(pytanie)) return true
else return false;
}