final int two_fifty_five_hex = 0xFF
final int two_fifty_five_dec = 255
One is in hex but the other is in decimal! Watch out, make sure you use the correct 255, not the other 255.
// We have this enum.
enum Formula {
case proposition(String)
indirect case negation(Formula)
indirect case operation(op: String, lhs: Formula, rhs: Formula)
var nnf: Formula { /* ... */ }
}
// And now ...
switch formula.nnf {
case .proposition(_):
return formula.nnf
case .negation(_):
return formula.nnf
case .operation(_, _, _):
return formula.nnf
}
/// <summary>
/// Builds the suffixs for the request sequence number
/// </summary>
/// <param name="i"></param>
/// <returns></returns>
public static string GetSequenceNumber(int i)
{
string strCount = string.Empty;
string increase = string.Empty;
int count;
strCount = i.ToString();
count = strCount.Length;
//Add 0 infront of the index to make a 4 digit number
if (count < 5)
{
for (int j = 0; j < (4 - count); j++)
{
increase = increase + "0";
}
strCount = increase + strCount;
}
return strCount;
}
public class NullableFloatToNullableDoubleConverter : ITypeConverter<float?, double?>
{
public double? Convert(float? source, double? destination, ResolutionContext context)
{
if (source == null)
{
return null;
}
var floatAsString = source.Value.ToString(CultureInfo.InvariantCulture);
return double.Parse(floatAsString);
}
}
if (!response ||
!response.data ||
!response.data.success ||
response.data.success == false ) {
//process stuff
}
Not talking about the '===' warning, here
$guard = ($vars->a_payment) + (0) * $price;
if ($bless >= $guard) {
$amount = $bless;
}
Why not to write just 1 line?! $amount = max($bless, $vars->a_payment);
public static int findSplitVariable(LinkedList<ByteDataRow> matrix) {
LinkedList<ByteDataRow> list = new LinkedList<ByteDataRow>();
int maxNoOfZeros = 0;
int maxNoOfOnes = 0;
int varId = -1;
int[] NoOfOnesInColumn = new int[matrix.get(0).getInVars().length];
for (ByteDataRow bdr : matrix) {
int tmpNoOfZeros = bdr.getNumberOfZeros();
if (maxNoOfZeros < tmpNoOfZeros) {
list.clear();
list.add(bdr.clone());
maxNoOfZeros = tmpNoOfZeros;
} else if (maxNoOfZeros == tmpNoOfZeros) {
list.add(bdr.clone());
}
}
for (ByteDataRow bdr : list) {
byte[] vars = bdr.getInVars();
for (int i = 0; i < vars.length; i++) {
NoOfOnesInColumn[i] = NoOfOnesInColumn[i]
+ Byte.compare(vars[i], Byte.parseByte("0"));
if (NoOfOnesInColumn[i] > maxNoOfOnes) {
maxNoOfOnes = NoOfOnesInColumn[i];
varId = i;
}
}
}
return varId;
}
public static int findSplitVariable(LinkedList<ByteDataRow> matrix, int varIdx) {
LinkedList<ByteDataRow> list = new LinkedList<ByteDataRow>();
int maxNoOfZeros = 0;
int maxNoOfOnes = 0;
int varId = -1;
int[] NoOfOnesInColumn = new int[matrix.get(0).getInVars().length];
// Wybierz kostkÍ z najwiÍkszπ liczbπ zer.
for (ByteDataRow bdr : matrix) {
int tmpNoOfZeros = bdr.getNumberOfZeros();
if (maxNoOfZeros < tmpNoOfZeros) {
list.clear();
list.add(bdr.clone());
maxNoOfZeros = tmpNoOfZeros;
} else if (maxNoOfZeros == tmpNoOfZeros) {
list.add(bdr.clone());
}
}
for (ByteDataRow bdr : list) {
byte[] vars = bdr.getInVars();
for (int i = 0; i < vars.length; i++) {
NoOfOnesInColumn[i] = NoOfOnesInColumn[i]
+ Byte.compare(vars[i], Byte.parseByte("0"));
if (NoOfOnesInColumn[i] > maxNoOfOnes) {
maxNoOfOnes = NoOfOnesInColumn[i];
varId = i;
}
}
}
return varId;
}
There are two methods findSplitVariable. Second one takes extra parameter (varIdx) that is not used anywhere.
if (code === null) {
return null;
} else {
return code;
}
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)
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
int main(void){
void run_func(char *map[], char *fnt , char *km , float *x , float *y , int line , int row , int lift );
char *long_met[3][8] = {{"mile","0.621371" , "yard","1093.61" , "fut","3280.84" , "duim","39370.1" } ,
{ "mile" ,"1.60934" , "yard","0.0009144" , "fut","0.0003048" , "duim","0.0000254"},
{"kilometer","1" , "meter","1000" , "stmeter","100000" , "mmeter","1000000" } };
char *amount[3][4] = { { "gallon" , "0.264172" , "quarta" , "1.05669" } ,
{"gallon" , " 3.78541" , "quarta" , "0.946353" },
{"litr" , "1" , "mililitr" , "1000" }};
char *mass[3][8] = { {"eng.tonna","0.984207" , "amer.tonna","1.10231" , "stone","157.473" , "funt","2204.62" } ,
{ "eng.tonna" , "1.01605" , "amer.tonna", "0.907185" , "stone","0.00635029" , "funt","0.000453592"},
{"tonna","1" , "kilogram" , "1000" , "miligram","100000" , "microgram","1000000" }};
char **cp;
char *buf_data;
char *fnt_sys;
char *mtr_sys;
char *word[100];
while(1){
int bg = 0,convert_ch = 3,y = 0, d = 0, numb = 0;
float mn =0 , xm = 0 ;
printf("%s", "enter data for converter: ");
fgets( (char *) word, 99 ,stdin);
buf_data = strtok((char *) word, " ");
if( ! strcmp(buf_data, "funt.sys" ) ){
convert_ch = 0;
}
else if( ! strcmp(buf_data, "metric.sys" ) ){
convert_ch = 1;
}
for( bg = 0 ; buf_data != NULL; buf_data = strtok(NULL, " ") , bg++ ) {
switch(bg){
case 1:
if( !strcmp("long_met" , buf_data ) ){
y = sizeof(*long_met) / sizeof(long_met[0][0]);
d = sizeof(long_met) / sizeof(long_met[0][0]);
cp = &long_met[convert_ch][0] ;
}
else if(!strcmp("amount" , buf_data ) ){
y = sizeof(*amount) / sizeof(amount [0][0]);
d = sizeof(amount) / sizeof(amount[0][0]);
cp = &amount[convert_ch][0] ;
}
else if(!strcmp("mass" , buf_data ) ){
y = sizeof(*mass ) / sizeof(mass[0][0]);
d = sizeof(mass ) / sizeof(mass[0][0]);
cp = &mass[convert_ch][0] ;
}
break;
case 2:
fnt_sys = buf_data;
break;
case 3:
mtr_sys = buf_data;
break;
case 4:
numb = atoi(buf_data);
break;
}
}
if( !y || !d || !cp || convert_ch == 3 || !numb ){
puts("error");
}
else{
run_func( cp, fnt_sys , mtr_sys , &mn , &xm , y , d , convert_ch );
if( !mn || !xm ){
puts("error");
} else{
printf("%f\n" , !convert_ch ? (mn / xm ) * numb : ( mn * xm ) * numb );
}
}
}
return 0;
}
void run_func(char *map[], char *fnt , char *km , float *x , float *y , int line , int row , int lift ){
int m ;
if( ( lift ) ){
row -= line;
}
for( m = 0 ; m <= line ; m++){
if(!strcmp(fnt,map[m])){
*x = atof(map[m + 1] ) ;
break;
}
}
for( m = (row - line) ; m <= row - 1 ; m++){
if( !strcmp( km , map[m] ) ){
*y = atof(map[m + 1 ] );
break;
}
}
}
<Image source={ this.props.pickupOrDropoff == "pickup"
? i.pickup
? iconBlue
: iconWhite
: i.dropoff
? iconBlue
: iconWhite} style={{
height:this.props.pickupOrDropoff == "pickup"
? i.pickup
? 30
: i.sign === 'D' ? 30 : 35
: i.dropoff
? 30
: i.sign === 'D' ? 30 : 35,
marginRight:10 ,
width: this.props.pickupOrDropoff == "pickup"
? i.pickup
? 40
: 40
: i.dropoff
? 40
: 40
,resizeMode:'contain'}}/>
I love when the code is neat...
elsif ( $att =~ m/!!ARRAY!!/ ) { # Updated to allow us to get data from an Array -
&Debug("get_value_from_hash:: parsing the ARRAY attribute - $att");
my ( $key1, $key2, $key3, $key4, $key5, $key6 ) = split( /\./, $att );
#&Debug("get_value_from_hash:: key1=$key1, key2=$key2, key3=$key3, key4=$key4, key5=$key5");
if ( defined $key6 ) {
if ( $key5 =~ m/!!ARRAY!!/ ) {
for my $item ( @{ $hash->{$key1}->{$key2}->{$key3}->{$key4} } ) { $value = $item->{$key6}; }
}
elsif ( $key4 =~ m/!!ARRAY!!/ ) {
for my $item ( @{ $hash->{$key1}->{$key2}->{$key3} } ) { $value = $item->{$key5}->{$key6}; }
}
elsif ( $key3 =~ m/!!ARRAY!!/ ) {
for my $item ( @{ $hash->{$key1}->{$key2} } ) { $value = $item->{$key4}->{$key5}->{$key6}; }
}
elsif ( $key2 =~ m/!!ARRAY!!/ ) {
for my $item ( @{ $hash->{$key1} } ) { $value = $item->{$key3}->{$key4}->{$key5}->{$key6}; }
}
elsif ( $key1 =~ m/!!ARRAY!!/ ) {
for my $item ( @{$hash} ) { $value = $item->{$key2}->{$key3}->{$key4}->{$key5}->{$key6}; }
}
}
elsif ( defined $key5 ) {
if ( $key4 =~ m/!!ARRAY!!/ ) {
for my $item ( @{ $hash->{$key1}->{$key2}->{$key3} } ) { $value = $item->{$key5}; }
}
elsif ( $key3 =~ m/!!ARRAY!!/ ) {
for my $item ( @{ $hash->{$key1}->{$key2} } ) { $value = $item->{$key4}->{$key5}; }
}
elsif ( $key2 =~ m/!!ARRAY!!/ ) {
for my $item ( @{ $hash->{$key1} } ) { $value = $item->{$key3}->{$key4}->{$key5}; }
}
elsif ( $key1 =~ m/!!ARRAY!!/ ) {
for my $item ( @{$hash} ) { $value = $item->{$key1}->{$key3}->{$key4}->{$key5}; }
}
}
elsif ( defined $key4 ) {
if ( $key3 =~ m/!!ARRAY!!/ ) {
for my $item ( @{ $hash->{$key1}->{$key2} } ) { $value = $item->{$key4}; }
}
elsif ( $key2 =~ m/!!ARRAY!!/ ) {
for my $item ( @{ $hash->{$key1} } ) { $value = $item->{$key3}->{$key4}; }
}
elsif ( $key1 =~ m/!!ARRAY!!/ ) {
for my $item ( @{$hash} ) { $value = $item->{$key1}->{$key3}->{$key4}; }
}
}
elsif ( defined $key3 ) {
if ( $key2 =~ m/!!ARRAY!!/ ) {
for my $item ( @{ $hash->{$key1} } ) { $value = $item->{$key3}; }
}
elsif ( $key1 =~ m/!!ARRAY!!/ ) {
for my $item ( @{$hash} ) { $value = $item->{$key3}; }
}
}
elsif ( defined $key2 ) {
if ( $key1 =~ m/!!ARRAY!!/ ) {
for my $item ( @{$hash} ) { $value = $item->{$key2}; }
}
}
}
elsif ( $att =~ m/!!HITS\[\d+\]!!/ ) {
&Debug("get_value_from_hash:: parsing the HITS attribute - $att");
my $id = $att;
$id =~ s/!!HITS\[(\d+)\]!!.*/$1/;
$att =~ s/!!HITS\[\d+\]!!\.//;
&Debug("get_value_from_hash:: parsing the attribute - $att");
my ( $key1, $key2, $key3, $key4, $key5, $key6 ) = split( /\./, $att );
#&Debug("get_value_from_hash:: id=$id, key1=$key1, key2=$key2, key3=$key3, key4=$key4, key5=$key5");
if ( defined $key6 ) {
$value = $$hash{hits}{hits}[$id]{$key1}{$key2}{$key3}{$key4}{$key5}{$key6};
}
elsif ( defined $key5 ) {
$value = $$hash{hits}{hits}[$id]{$key1}{$key2}{$key3}{$key4}{$key5};
}
elsif ( defined $key4 ) {
$value = $$hash{hits}{hits}[$id]{$key1}{$key2}{$key3}{$key4};
}
elsif ( defined $key3 ) {
$value = $$hash{hits}{hits}[$id]{$key1}{$key2}{$key3};
}
elsif ( defined $key2 ) {
$value = $$hash{hits}{hits}[$id]{$key1}{$key2};
}
}
elsif ( $att =~ m/!!DELIMITER!!.+!!/ ) {
&Debug("get_value_from_hash:: parsing the DELIMITER attribute - $att");
my $delimiter = $att;
$delimiter =~ s/!!DELIMITER!!(.*)!!.*/$1/;
$att =~ s/!!DELIMITER!!.+!!//;
&Debug("get_value_from_hash:: parsing the attribute - $att");
my ( $key1, $key2, $key3, $key4, $key5, $key6 ) = split( $delimiter, $att );
# &Debug("get_value_from_hash:: key1=$key1, key2=$key2, key3=$key3, key4=$key4, key5=$key5, key6=$key6");
if ( defined $key6 ) {
$value = $$hash{$key1}{$key2}{$key3}{$key4}{$key5}{$key6};
}
elsif ( defined $key5 ) {
$value = $$hash{$key1}{$key2}{$key3}{$key4}{$key5};
}
elsif ( defined $key4 ) {
$value = $$hash{$key1}{$key2}{$key3}{$key4};
}
elsif ( defined $key3 ) {
$value = $$hash{$key1}{$key2}{$key3};
}
elsif ( defined $key2 ) {
$value = $$hash{$key1}{$key2};
}
}
else {
&Debug("get_value_from_hash:: parsing the attribute - $att");
my ( $key1, $key2, $key3, $key4, $key5, $key6 ) = split( /\./, $att );
#&Debug("get_value_from_hash:: key1=$key1, key2=$key2, key3=$key3, key4=$key4, key5=$key5");
if ( defined $key6 ) {
$value = $$hash{$key1}{$key2}{$key3}{$key4}{$key5}{$key6};
}
elsif ( defined $key5 ) {
$value = $$hash{$key1}{$key2}{$key3}{$key4}{$key5};
}
elsif ( defined $key4 ) {
$value = $$hash{$key1}{$key2}{$key3}{$key4};
}
elsif ( defined $key3 ) {
$value = $$hash{$key1}{$key2}{$key3};
}
elsif ( defined $key2 ) {
$value = $$hash{$key1}{$key2};
}
}
When you try to debug, why value is not filled, and find this...
let already_in = True;
while (already_in) {
let random_index = Math.floor(arr.length * Math.random());
let already_in = False;
for (ex of exs) {
if (ex.id === arr[random_index].id) {
already_in = True;
}
}
}
Yes, this is JavaScript, and yes it didn't work. Found while reviewing some code
def get_verified_infos(request):
try:
# request logic here
return data
except Exception:
logger.error(
'Request to XXX was unsuccessful, '
'Will retry till max recursion! Retrying...'
)
return get_verified_infos(request)
Used for OpenID authentication
protected override void OnStartup(StartupEventArgs e)
{
Current.DispatcherUnhandledException += ApplicationUnhandledException;
base.OnStartup(e);
#if (DEBUG)
RunInDebugMode(e.Args);
#else
RunInReleaseMode(e.Args);
#endif
}
#endregion
private static void RunInReleaseMode(string[] args)
{
AppDomain.CurrentDomain.UnhandledException += AppDomainUnhandledException;
try
{
SplashScreen screen = new SplashScreen(@"Images\splashscreen.png");
screen.Show(true, true);
RunInDebugMode(args);
}
catch (Exception ex)
{
HandleException(ex);
}
}
private static void RunInDebugMode(string[] args)
{
var bootstrapper = new Bootstrapper();
bootstrapper.Run();
}