double func_atof(char *p){
double integer = 0.0, div = 1.0 , fract = 0.0 , sign = 1.0;
if( *p == 45 ){sign = -1.0, *p++ ; }
while ( isdigit(*p) ) {
integer = ( *p++ ) + (10.0 * integer) - 48.0 ;
}
if(*p == 46 ){
(*p++ ) ;
while ( isdigit(*p) ) {
fract = ( *p++ ) + (10.0 * fract) - 48.0 ;
div *= 10;
}
}
return (integer + fract / div ) * sign ;
}
private static final double RESULT_OF_DIVISION_BY_0 = 9.99;
public static double getPercentageDifference(long currentResult, long previousResult) {
if (previousResult == 0 && currentResult == 0) {
return 0;
} else if (previousResult == 0) {
return RESULT_OF_DIVISION_BY_0;
} else {
return (currentResult - previousResult) * 1.0 / previousResult;
}
}
Public Shared Function CompeleteDateStr(DateStr As String) As String
'MBS 96-09-25: High Caliber DataEntry
Dim DateVal = CType(DateStr, Integer)
If DateVal < 1 Then Return ""
If DateVal < maxDay Then 'DayOnly
Return MakeJalaliDate(curYear, curMonth, DateVal, _4DigitYear)
ElseIf DateVal > maxDay Then
Dim YearPiece? As Short = Nothing, MonthPiece? As Byte = Nothing, DayPiece As Byte
Select Case DateVal
Case Is < 100
MonthPiece = (DateVal \ 10) Mod 10
DayPiece = DateVal Mod 10
If IsValidMonth(MonthPiece) AndAlso IsValidDay(DayPiece, MonthPiece, curYear) Then Return MakeJalaliDate(curYear, MonthPiece, DayPiece, _4DigitYear)
Case Is < 1000
MonthPiece = DateVal \ 10
DayPiece = DateVal Mod 10
If IsValidMonth(MonthPiece) AndAlso IsValidDay(DayPiece, MonthPiece, curYear) Then Return MakeJalaliDate(curYear, MonthPiece, DayPiece, _4DigitYear)
MonthPiece = (DateVal \ 100) Mod 10
DayPiece = DateVal Mod 100
If IsValidMonth(MonthPiece) AndAlso IsValidDay(DayPiece, MonthPiece, curYear) Then Return MakeJalaliDate(curYear, MonthPiece, DayPiece, _4DigitYear)
DayPiece = DateVal \ 10
MonthPiece = DateVal Mod 10
If IsValidMonth(MonthPiece) AndAlso IsValidDay(DayPiece, MonthPiece, curYear) Then Return MakeJalaliDate(curYear, MonthPiece, DayPiece, _4DigitYear)
DayPiece = (DateVal \ 100) Mod 10
MonthPiece = DateVal Mod 100
If IsValidMonth(MonthPiece) AndAlso IsValidDay(DayPiece, MonthPiece, curYear) Then Return MakeJalaliDate(curYear, MonthPiece, DayPiece, _4DigitYear)
Case Is < 10000
MonthPiece = DateVal \ 100
DayPiece = DateVal Mod 100
If IsValidMonth(MonthPiece) AndAlso IsValidDay(DayPiece, MonthPiece, curYear) Then Return MakeJalaliDate(curYear, MonthPiece, DayPiece, _4DigitYear)
MonthPiece = DateVal Mod 100
DayPiece = DateVal \ 100
If IsValidMonth(MonthPiece) AndAlso IsValidDay(DayPiece, MonthPiece, curYear) Then Return MakeJalaliDate(curYear, MonthPiece, DayPiece, _4DigitYear)
DayPiece = DateVal \ 100
MonthPiece = DateVal Mod 100
If IsValidMonth(MonthPiece) AndAlso IsValidDay(DayPiece, MonthPiece, curYear) Then Return MakeJalaliDate(curYear, MonthPiece, DayPiece, _4DigitYear)
DayPiece = DateVal Mod 100
MonthPiece = DateVal \ 100
If IsValidMonth(MonthPiece) AndAlso IsValidDay(DayPiece, MonthPiece, curYear) Then Return MakeJalaliDate(curYear, MonthPiece, DayPiece, _4DigitYear)
MonthPiece = (DateVal \ 10) Mod 10
YearPiece = DateVal \ 100
If IsValidMonth(MonthPiece) Then
DayPiece = DateVal Mod 10
If IsValidDay(DayPiece, MonthPiece, YearPiece) Then Return MakeJalaliDate(YearPiece, MonthPiece, DayPiece, _4DigitYear)
Else
MonthPiece = (DateVal \ 100) Mod 10
YearPiece = DateVal Mod 100
DayPiece = DateVal \ 1000
If IsValidMonth(MonthPiece) AndAlso IsValidDay(DayPiece, MonthPiece, YearPiece) Then Return MakeJalaliDate(YearPiece, MonthPiece, DayPiece, _4DigitYear)
End If
Case Is < 100000
Dim DaySize As Byte = 2
MonthPiece = (DateVal Mod 1000) \ 10
If Not IsValidMonth(MonthPiece) Then
MonthPiece = (DateVal \ 100) Mod 10
DaySize = 1
If Not IsValidMonth(MonthPiece) Then Return ""
End If
YearPiece = DateVal \ 1000
DayPiece = DateVal Mod 10 ^ DaySize
If IsValidDay(DayPiece, MonthPiece, YearPiece) Then Return MakeJalaliDate(YearPiece, MonthPiece, DayPiece)
YearPiece = DateVal Mod 100
DayPiece = DateVal \ (10000 \ (10 ^ DaySize))
If IsValidDay(DayPiece, MonthPiece, YearPiece) Then Return MakeJalaliDate(YearPiece, MonthPiece, DayPiece)
Case Is < 1000000
MonthPiece = (DateVal Mod 10000) \ 100
If IsValidMonth(MonthPiece) Then
YearPiece = DateVal \ 10000
DayPiece = DateVal Mod 100
If IsValidDay(DayPiece, MonthPiece, YearPiece) Then Return MakeJalaliDate(YearPiece, MonthPiece, DayPiece, _4DigitYear)
YearPiece = DateVal Mod 100
DayPiece = DateVal \ 10000
If IsValidDay(DayPiece, MonthPiece, YearPiece) Then Return MakeJalaliDate(YearPiece, MonthPiece, DayPiece, _4DigitYear)
End If
YearPiece = DateVal \ 100
If YearPiece > 1300 AndAlso YearPiece < 1500 Then
MonthPiece = (DateVal \ 10) Mod 10
DayPiece = DateVal Mod 10
If IsValidMonth(MonthPiece) AndAlso IsValidDay(DayPiece, MonthPiece, YearPiece) Then Return MakeJalaliDate(YearPiece, MonthPiece, DayPiece, _4DigitYear)
End If
YearPiece = DateVal Mod 10000
If YearPiece > 1300 AndAlso YearPiece < 1400 Then
DayPiece = DateVal \ 100000
MonthPiece = (DateVal \ 10000) Mod 10
If IsValidMonth(MonthPiece) AndAlso IsValidDay(DayPiece, MonthPiece, YearPiece) Then Return MakeJalaliDate(YearPiece + If(_4DigitYear, 0, -1300), MonthPiece, DayPiece, _4DigitYear)
End If
Case Is < 10000000
Dim DaySize As Byte = 2
MonthPiece = (DateVal Mod 1000) \ 10
If Not IsValidMonth(MonthPiece) Then
MonthPiece = (DateVal \ 100) Mod 10
DaySize = 2
If Not IsValidMonth(MonthPiece) Then Return ""
End If
YearPiece = DateVal \ 1000
DayPiece = DateVal Mod 10 ^ DaySize
If IsValidDay(DayPiece, MonthPiece, YearPiece) Then Return MakeJalaliDate(YearPiece, MonthPiece, DayPiece)
YearPiece = DateVal Mod 10000
DayPiece = DateVal \ (100000 * (10 ^ DaySize))
If IsValidDay(DayPiece, MonthPiece, YearPiece) Then Return MakeJalaliDate(YearPiece, MonthPiece, DayPiece)
Case Is < 100000000
MonthPiece = (DateVal Mod 10000) \ 100 '13961229
If IsValidMonth(MonthPiece) Then
YearPiece = DateVal \ 10000
DayPiece = DateVal Mod 100
If IsValidDay(DayPiece, MonthPiece, YearPiece) Then Return MakeJalaliDate(YearPiece, MonthPiece, DayPiece, _4DigitYear)
YearPiece = DateVal Mod 10000
DayPiece = DateVal \ 1000000
If IsValidDay(DayPiece, MonthPiece, YearPiece) Then Return MakeJalaliDate(YearPiece, MonthPiece, DayPiece, _4DigitYear)
End If
End Select
Return ""
End If
End Function
this code is so wrong in so many different levels
// check if user is valid or not
ValidUserValidationResult userValidationResult = validUserValidator.validateUser(validationRequest);
for (int i = 0;i < n / 2;i++)
{
while (num[a[p].id].n == 0 || num[num[a[p].id].nxt].n == 0)
{
p++;
}
printf("%d %d ", num[a[p].id].n, num[num[a[p].id].nxt].n);
num[a[p].id].n = 0;
num[num[a[p].id].nxt].n = 0;
num[num[a[p].id].lst].nxt = num[num[a[p].id].nxt].nxt;
num[num[num[a[p].id].nxt].nxt].lst = num[a[p].id].lst;
}
const handleBoolean = value => {
switch (value) {
case "true":
return true;
case true:
return "true";
case "false":
return false;
case false:
return "false"
default:
return null;
}
}
<?php
if(!defined('WPINC')) // MUST have WordPress.
exit ('Do not access this file directly.');
if(!class_exists('pluginName_options_page_class'))
{
/**
* Menu page blah
*
* @package blah
* @since 140617
*/
class pluginName_options_page_class
{
public function __construct()
{
echo '<div class="wrap menu-page">'."\n";
echo '<div class="wp-header-end"></div>'."\n";
echo '<div class="menu-page-toolbox">'."\n";
pluginName_some_other_class::display();
echo '</div>'."\n";
echo '<h2>Options</h2>'."\n";
echo '<table class="menu-page-table">'."\n";
echo '<tbody class="menu-page-table-tbody">'."\n";
echo '<tr class="menu-page-table-tr">'."\n";
echo '<td class="menu-page-table-l">'."\n";
echo '<form method="post" name="plugin_options_form" id="plugin--options-form" autocomplete="off">'."\n";
echo '<input type="hidden" name="plugin_options_save" id="plugin--options-save" value="'.esc_attr(wp_create_nonce('plugin--options-save')).'" />'."\n";
echo '<div class="menu-page-group" title="Account Details">'."\n";
/* includes things like this gem */
echo (!is_multisite() || !pluginName_utils_conds::is_multisite_farm() || is_main_site()) ? '<p>[ Really Long message about something ]</p>'."\n" : '';
/* ... continues until end ... */
echo '</div>'."\n";
}
}
}
new pluginName_options_page_class ();
The entire file is a single class with a constructor. The constructor is ~ 1150 lines of echo statements with a few PHP conditionals thrown in. There are no other methods. The class is instantiated as soon as it is defined. Clever...
Native XML structure:
<?xml version="1.0" encoding="utf-8" ?>
<tree>
<node name="root">
<node name="TELEVISIONS">
<node name="TUBE"/>
<node name="LCD"/>
<node name="PLASMA"/>
</node>
<node name="PORTABLE ELECTRONICS">
<node name="MP3 PLAYERS">
<node name="FLASH"/>
</node>
<node name="CD PLAYERS"/>
<node name="2 WAY RADIOS"/>
</node>
</node>
</tree>
Flattened XML structure (example 1):
<tree>
<node key="0">root</node>
<node key="1" parent="0">TELEVISIONS</node>
<node key="2" parent="1">TUBE</node>
<node key="3" parent="1">LCD</node>
<node key="4" parent="1">PLASMA</node>
<node key="5" parent="0">PORTABLE ELECTRONICS</node>
<node key="6" parent="5">MP3 PLAYERS</node>
<node key="7" parent="6">FLASH</node>
<node key="8" parent="5">CD PLAYERS</node>
<node key="9" parent="5">2 WAY RADIOS</node>
</tree>
Flattened XML structure (example 2):
<tree>
<node>
<name>root</name>
<depth>0</depth>
</node>
<node>
<name>TELEVISIONS</name>
<depth>1</depth>
</node>
<node>
<name>TUBE</name>
<depth>2</depth>
</node>
<node>
<name>LCD</name>
<depth>2</depth>
</node>
<node>
<name>PLASMA</name>
<depth>2</depth>
</node>
<node>
<name>PORTABLE ELECTRONICS</name>
<depth>1</depth>
</node>
<node>
<name>MP3 PLAYERS</name>
<depth>2</depth>
</node>
<node>
<name>FLASH</name>
<depth>3</depth>
</node>
<node>
<name>CD PLAYERS</name>
<depth>2</depth>
</node>
<node>
<name>2 WAY RADIOS</name>
<depth>2</depth>
</node>
</tree>
function focused(evt, errors) {
let form = evt.target
const output = errors.map((error)=> {
// Find first component with error on form and set focus to it
let focusedInput = (Object.keys(error) == "phonebookId") ? Object.keys(error) :
(Object.keys(error) == "phonebook_str") ? Object.keys(error) :
(Object.keys(error) == "message") ? Object.keys(error) :
(Object.keys(error) == "image") ? Object.keys(error) :
(Object.keys(error) == "buttonLink") ? Object.keys(error) :
(Object.keys(error) == "messageSms") ? Object.keys(error) : false
return focusedInput.shift()
})
const selector = output.shift()
form.querySelector('[id="' + selector + '"]').focus()
return selector
Shitcode
spring.datasource.password=#{@secretsManager.getJsonField('${DSP_DB_SECRET:}', 'password', @secretsManager.getString('${DSP_DB_PASSWORD_SECRET:}', '${DSP_DB_PASSWORD:}'))}
String boot, 3 env variables written as string containing code executable code which cannot be verified by compiler. Welcome to Java
String s = "string";
String.valueOf(s).toString();
// just to make sure it's a damn string
while(!s instanceof String) {
String.valueOf(s).toString();
}
public static function getUser(){
return \App\Models\User::all();
}
if((strtotime(date("Y-m-d"))-strtotime(date("Y-m-d", filemtime($filename))))/(3600)<=$config->hourDiff) return true; else return false;
please notice the brackets around 3600
if (preg_match("/^N/",$postcode)) {
if (preg_match("/^NW/", $postcode)) {
if (!preg_match("/^NW1/", $postcode)) {
// NORTH WEST (NW2, NW3, NW4, NW5, NW6, NW7, NW8, NW9, NW10)
$property['Prop_area'] = 'NW';
} else {
// NW1 which is Central
$property['Prop_area'] = 'SW';
}
} else {
// NORTH (N1, N2, N3, N4, N5 etc)
$property['Prop_area'] = 'N';
}
} else if (preg_match("/^W/",$postcode)) {
if (
!preg_match("/^W1 /",$postcode)
&& !preg_match("/^W2 /",$postcode)
&& !preg_match("/^W8/",$postcode)
&& !preg_match("/^W11/",$postcode)
) {
// WEST includes (W3, W4, W5, W6, W7, W9, W10, W12, W13, W14)
$property['Prop_area'] = 'W';
} else {
//W1 and W2, W8, W11 which are Central
$property['Prop_area'] = 'SW';
}
} else {
if (
preg_match("/^SW/",$postcode)
|| preg_match("/^EC/",$postcode)
|| preg_match("/^WC/",$postcode)
) {
// CENTRAL includes (W1, W2, EC, WC, NW1, SW1, SW3, SW5, SW7, W8, W11)
$property['Prop_area'] = 'SW';
} else {
// OTHER includes South and East and everything else
return 'SE';
}
}
cd /some/directory
rm -rf *
I regularly see these two lines in Bash scripts I don't understand but some programmers think you need a CD command before any command, and they also don't know that paths can be part of parameters (which explains why they use many CD commands)