问:
Powerful algorithms too complex to implement
What are some algorithms of legitimate utility that are simply too complex to implement?

Let me be clear: I'm not looking for algorithms like the current asymptotic optimal matrix multiplication algorithm, which is reasonable to implement but has a constant that makes it useless in practice. I'm looking for algorithms that could plausibly have practical value, but are so difficult to code that they have never been implemented, only implemented in extremely artificial settings, or only implemented for remarkably special-purpose applications.

Also welcome are near-impossible-to-implement algorithms that have good asymptotics but would likely have poor real performance.

答:
I don't think there is any algorithm with practical use that has never been coded, but there are plenty that are difficult to code.

An example of an algorithm that is asymptotically optimal, but very difficult to code is Chazelle's O(n) polygon triangulation algorithm. According to Skiena (author of The Algorithm Design Manual), "[the] algorithm is quite hopeless to implement."

In general, triangulation and other computational geometry algorithms (such as 3D convex hull, and Voronoi diagrams) can be quick tricky to implement. A lot of the trickiness comes down to handling floating point inaccuracies.


来源: stackexchange

问:
TextInput Typed Text not appearing on android
I'm new to react-native and am trying to make an app for both android and iOS at the same time.

Currently, I have a login screen set up, but both the typed text and placeholder text used within textInput is not showing in the app for android (works fine for iPhone).

Here is the code snippet and style sheet:

```<code>    'use strict';
import React, { Component } from 'react'
var Dimensions = require('Dimensions');
var windowSize = Dimensions.get('window');

import {
  AppRegistry,
  StyleSheet,
  View,
  Text,
  TextInput,
  Image
} from 'react-native';

class LoginPage extends Component {
  constructor() {
    super()
    this.state = {
        username: '',
        password: ''
    }
  }
  render() {
    return (
        <View style={styles.container}>
            <Image style={styles.bg} source={require('./Resources/orangebackground.png')} />
            <View style={styles.header}>
                <Image source={require('./Resources/logo.png')} />
            </View>
            <View style={styles.inputs}>
                <View style={styles.inputContainer}>
                    <Image style={styles.inputUsername} source={require('./Resources/un.png')}/>
                    <TextInput
                        style={[styles.input, styles.whiteFont]}
                        underlineColorAndroid={'white'}
                        placeholder='Username'
                        placeholderTextColor="white"
                        //value={this.state.username}
                    />
                </View>
                <View style={styles.inputContainer}>
                    <Image style={styles.inputPassword} source={require('./Resources/pw.png')}/>
                    <TextInput
                        password={true}
                        style={[styles.input, styles.whiteFont]}
                        placeholder="Password"
                        placeholderTextColor="#FFF"
                        underlineColorAndroid={'transparent'}
                        //value={this.state.password}
                    />
                </View>
                <View style={styles.forgotContainer}>
                    <Text style={styles.greyFont}>Forgot Password</Text>
                </View>
            </View>
            <View style={styles.signin}>
                <Text style={styles.whiteFont}>Sign In</Text>
            </View>
            <View style={styles.signup}>
                <Text style={styles.greyFont}>Don't have an account?<Text style={styles.whiteFont}>  Sign Up</Text></Text>
            </View>
        </View>
    );
  }
}

var styles = StyleSheet.create({
    container: {
      flexDirection: 'column',
      flex: 1,
      backgroundColor: 'transparent'
    },
    bg: {
        position: 'absolute',
        left: 0,
        top: 0,
        width: windowSize.width,
        height: windowSize.height
    },
    header: {
        justifyContent: 'center',
        alignItems: 'center',
        flex: .5,
        backgroundColor: 'transparent'
    },
    mark: {
        width: 150,
        height: 150
    },
    signin: {
        backgroundColor: '#FF3366',
        padding: 20,
        alignItems: 'center'
    },
    signup: {
      justifyContent: 'center',
      alignItems: 'center',
      flex: .15
    },
    inputs: {
        marginTop: 10,
        marginBottom: 10,
        flex: .25
    },
    inputPassword: {
        marginLeft: 15,
        width: 20,
        height: 21
    },
    inputUsername: {
      marginLeft: 15,
      width: 20,
      height: 20
    },
    inputContainer: {
        padding: 10,
        borderWidth: 1,
        borderBottomColor: '#CCC',
        borderColor: 'transparent'
    },
    input: {
        position: 'absolute',
        left: 61,
        top: 12,
        right: 0,
        height: 20,
        fontSize: 14
    },
    forgotContainer: {
      alignItems: 'flex-end',
      padding: 15,
    },
    greyFont: {
      color: '#D8D8D8'
    },
    whiteFont: {
      color: '#FFF'
    }
})
</code>```

Any help is appreciated. Thank you.

答:
I recently had this issue, and I solved it by adding paddingVertical: 0 to the style of the input and by set underlineColorAndroid="transparent" prop. The style can be same for both platforms this way. It seems like there is some default vertical padding on android.

There is also related issue on the Github of React Native.

ContentLicense: CC BY-SA 3.0

Body:
I'm new to react-native and am trying to make an app for both android and iOS at the same time.

Currently, I have a login screen set up, but both the typed text and placeholder text used within textInput is not showing in the app for android (works fine for iPhone).

Here is the code snippet and style sheet:

    'use strict';
import React, { Component } from 'react'
var Dimensions = require('Dimensions');
var windowSize = Dimensions.get('window');

import {
  AppRegistry,
  StyleSheet,
  View,
  Text,
  TextInput,
  Image
} from 'react-native';

class LoginPage extends Component {
  constructor() {
    super()
    this.state = {
        username: '',
        password: ''
    }
  }
  render() {
    return (
        <View style={styles.container}>
            <Image style={styles.bg} source={require('./Resources/orangebackground.png')} />
            <View style={styles.header}>
                <Image source={require('./Resources/logo.png')} />
            </View>
            <View style={styles.inputs}>
                <View style={styles.inputContainer}>
                    <Image style={styles.inputUsername} source={require('./Resources/un.png')}/>
                    <TextInput
                        style={[styles.input, styles.whiteFont]}
                        underlineColorAndroid={'white'}
                        placeholder='Username'
                        placeholderTextColor="white"
                        //value={this.state.username}
                    />
                </View>
                <View style={styles.inputContainer}>
                    <Image style={styles.inputPassword} source={require('./Resources/pw.png')}/>
                    <TextInput
                        password={true}
                        style={[styles.input, styles.whiteFont]}
                        placeholder="Password"
                        placeholderTextColor="#FFF"
                        underlineColorAndroid={'transparent'}
                        //value={this.state.password}
                    />
                </View>
                <View style={styles.forgotContainer}>
                    <Text style={styles.greyFont}>Forgot Password</Text>
                </View>
            </View>
            <View style={styles.signin}>
                <Text style={styles.whiteFont}>Sign In</Text>
            </View>
            <View style={styles.signup}>
                <Text style={styles.greyFont}>Don't have an account?<Text style={styles.whiteFont}>  Sign Up</Text></Text>
            </View>
        </View>
    );
  }
}

var styles = StyleSheet.create({
    container: {
      flexDirection: 'column',
      flex: 1,
      backgroundColor: 'transparent'
    },
    bg: {
        position: 'absolute',
        left: 0,
        top: 0,
        width: windowSize.width,
        height: windowSize.height
    },
    header: {
        justifyContent: 'center',
        alignItems: 'center',
        flex: .5,
        backgroundColor: 'transparent'
    },
    mark: {
        width: 150,
        height: 150
    },
    signin: {
        backgroundColor: '#FF3366',
        padding: 20,
        alignItems: 'center'
    },
    signup: {
      justifyContent: 'center',
      alignItems: 'center',
      flex: .15
    },
    inputs: {
        marginTop: 10,
        marginBottom: 10,
        flex: .25
    },
    inputPassword: {
        marginLeft: 15,
        width: 20,
        height: 21
    },
    inputUsername: {
      marginLeft: 15,
      width: 20,
      height: 20
    },
    inputContainer: {
        padding: 10,
        borderWidth: 1,
        borderBottomColor: '#CCC',
        borderColor: 'transparent'
    },
    input: {
        position: 'absolute',
        left: 61,
        top: 12,
        right: 0,
        height: 20,
        fontSize: 14
    },
    forgotContainer: {
      alignItems: 'flex-end',
      padding: 15,
    },
    greyFont: {
      color: '#D8D8D8'
    },
    whiteFont: {
      color: '#FFF'
    }
})

Any help is appreciated. Thank you.


问:
How to unzip the files stored in hdfs using spark java
```<code>List<String> list= jsc.wholeTextFiles(hdfsPath).keys().collect();
        for (String string : list) {
        System.out.println(string);
        }
</code>```

Here i am getting all the zip files.From here i am unable to proceed how to extract each file and store into hdfs path with same zipname folder

答:
With gzip files, wholeTextFiles should gunzip everything automatically.
With zip files however, the only way I know is to use binaryFiles and to unzip the data by hand.

```<code>sc
    .binaryFiles(hdfsDir)
    .mapValues(x=> {
        var result = scala.collection.mutable.ArrayBuffer.empty[String]
        val zis = new ZipInputStream(x.open())
        var entry : ZipEntry = null
        while({entry = zis.getNextEntry();entry} != null) {
            val scanner = new Scanner(zis)
            while (sc.hasNextLine()) {result+=sc.nextLine()}
        }
        zis.close()
        result
    }
</code>```

This gives you a (pair) RDD[String, ArrayBuffer[String]] where the key is the name of the file on hdfs and the value the unzipped content of the zip file (one line per element of the ArrayBuffer). If a given zip file contains more than one file, everything is aggregated. You may adapt the code to fit your exact needs. For instance, flatMapValues instead of mapValues would flatten everything (RDD[String, String]) to take advantage of spark's parallelism.

Note also that in the while condition, "{entry = is.getNextEntry();entry} could be replaced by (entry = is.getNextEntry()) in java. In scala however the result of an affectation is Unit so this would yield an infinite loop.

Body:
List<String> list= jsc.wholeTextFiles(hdfsPath).keys().collect();
        for (String string : list) {
        System.out.println(string);
        }

Here i am getting all the zip files.From here i am unable to proceed how to extract each file and store into hdfs path with same zipname folder

Body:
With gzip files, wholeTextFiles should gunzip everything automatically.
With zip files however, the only way I know is to use binaryFiles and to unzip the data by hand.

sc
    .binaryFiles(hdfsDir)
    .mapValues(x=> {
        var result = scala.collection.mutable.ArrayBuffer.empty[String]
        val zis = new ZipInputStream(x.open())
        var entry : ZipEntry = null
        while({entry = zis.getNextEntry();entry} != null) {
            val scanner = new Scanner(zis)
            while (sc.hasNextLine()) {result+=sc.nextLine()}
        }
        zis.close()
        result
    }

This gives you a (pair) RDD[String, ArrayBuffer[String]] where the key is the name of the file on hdfs and the value the unzipped content of the zip file (one line per element of the ArrayBuffer). If a given zip file contains more than one file, everything is aggregated. You may adapt the code to fit your exact needs. For instance, flatMapValues instead of mapValues would flatten everything (RDD[String, String]) to take advantage of spark's parallelism.

Note also that in the while condition, "{entry = is.getNextEntry();entry} could be replaced by (entry = is.getNextEntry()) in java. In scala however the result of an affectation is Unit so this would yield an infinite loop.

ContentLicense: CC BY-SA 4.0


问:
ICO takes forever to load
How do I tell a webpage that I don't want an ICO so it doesn't waste loadtime looking for it??

```<code><link rel="icon" type="images/png" href="" />
</code>```

If it's omitted, then it looks too!

答:
Hmm... One possible trick could be to point it to LOCAL location:

```<code><link rel="icon" type="images/png" href="http://127.0.0.1/no_icon.ico" />
</code>```

It will still look, but 127.0.0.1 is by definition local host so there's no network trip involved to discover that there's nothing to load.

From RFC 5735: Special-Use IPv4 Addresses:

127.0.0.0/8 - This block is assigned for use as the Internet host
     loopback address.  A datagram sent by a higher-level protocol to an
     address anywhere within this block loops back inside the host.  This
     is ordinarily implemented using only 127.0.0.1/32 for loopback.  As
     described in [RFC1122], Section 3.2.1.3, addresses within the entire
     127.0.0.0/8 block do not legitimately appear on any network anywhere.

ContentLicense: CC BY-SA 2.5

Title: ICO takes forever to load

Body:
How do I tell a webpage that I don't want an ICO so it doesn't waste loadtime looking for it??

<link rel="icon" type="images/png" href="" />

If it's omitted, then it looks too!

Body:
Hmm... One possible trick could be to point it to LOCAL location:

<link rel="icon" type="images/png" href="http://127.0.0.1/no_icon.ico" />

It will still look, but 127.0.0.1 is by definition local host so there's no network trip involved to discover that there's nothing to load.

From RFC 5735: Special-Use IPv4 Addresses:

127.0.0.0/8 - This block is assigned for use as the Internet host
     loopback address.  A datagram sent by a higher-level protocol to an
     address anywhere within this block loops back inside the host.  This
     is ordinarily implemented using only 127.0.0.1/32 for loopback.  As
     described in [RFC1122], Section 3.2.1.3, addresses within the entire
     127.0.0.0/8 block do not legitimately appear on any network anywhere.


问:
How to find out the command Visual Studio sends to MSBuild?
I'm trying to use MSBuild in a CI/CD engine, and I need to publish an ASP.NET Core MVC application using it.

I want to know what Visual Studio sends to the MSBuild when we build/publish a project, and send that exactly to MSBuild.

Is there anyway that we can find out the command Visual Studio 2017 sends to MSBuild to build/publish a .NET Core project?

Update: To those who say that VS uses MSBuild API, simply kill all MSBuild.exe processes, then build a project/solution via VS, and you'll see that MSBuild.exe is coming back into the processes list (viewed via Task Manager). So, what's the explanation? If VS uses API, then that API should run inside devenv.exe process and no instance of MSBuild.exe should appear inside Task Manager. Right?

Update 2: Does devenv.exe expose its publish functionality?

答: I hope those link and link helped you somehow, they are old but may give you some guidance to the solution you are lookin for.</p>


问:
Is there a simple way to create user/group in alfresco at startup?
Here is alfresco-demo-data, they create user, group and some pieces of repository. But if you look a little deeper into code and examine PeopleUsersGroupAcpExporter, you see that to create some users you need:

acp archive with xml file with about 10-15 properties for one user

every user must have password hash, passwprd2 hash and salt, e.g. it is unclear how to create user with test 123 password.

create several classes: PeopleUsersGroupAcpExporter,
DynamicBootstrapPatchPostProcessor, ResourcesResolver,
UsersImporterPatch, GroupsImporterPatch with a lot of code.

And finally this classes wrap (put) some data into spring bean definition.

Definitely there are must much simpler way to create/import user and group at alfresco start up.

Note 1

Here is very similar question, but they used authenticationService, whithout telling what type it is. There is org.jbpm.security.AuthenticationService and org.alfresco.service.cmr.security.AuthenticationService but both do not have any *create* methods

Note 2

Alfresco already has a feature csv import/expport user, but it is about users only. It do not provides attaching imported users to group automatically.

答:
If you define your users and groups in an LDAP directory such as OpenLDAP or Apache Directory Server then you can simply add about ten lines of config to your alfresco-global.properties file, and all your users and groups will be sync'd into Alfresco on every startup. This has the added advantages of:

allowing you to easily manage users and groups via widely-available tools,

not requiring any custom code or extra setup,

working for every instance of Alfresco you might have on your machine (if this is a dev setup), and

working for other applications in your environment (if this is a prod setup).


问:
php CANG does not using value 0
Hi there i have a little issue with my CANG(Complex Alpha Numeric Generator) in php,

the generator is not inserting the number 0 into string.

This is from my DB MySQL

Example :

AAAAACPZ next code is -> AAAAACP1

but it should be AAAAACP0 and after AAAAACP1

Can somebody help me please to solve this issue?

Search for CANG.php and have look on my CANG class at here.

I remember once i have done this in the previous version,

but after some time i decide it to delete all the codes

and later on i build new versions.

If anyone come up with something let me know.

Thanks in advance

A little explanation :

All the generation of strings depends on the settings provided.

For example a have range('A','Z') and range(0,9)

so after every Z should be number zero -> 0 and not number 1.

```<code><?php
class CANG {

    public $default_code_length = 1;
    public $default_code_type = 1;
    public $run_default_code = TRUE;
    public $run_random_code = TRUE;
    public $code_max_type = 8;

    public function __construct(){
        /*
        Nothing to do here but if you need to use it with CI must write :
        class CANG extends CI_Library {}
        and remove the double back slash below
        */
        //parent::__construct();
    }

    public function SetLength($SetLength=FALSE){
        if(is_numeric($SetLength)){
            $this->default_code_length = $SetLength;
        }
    }

    public function SetType($SetType=FALSE){
        if(is_numeric($SetType) AND $this->code_max_type>=$SetType){
            $this->default_code_type = $SetType;
        }
    }

    public function CodeCountRange($code_char_range=[]){
        $count_characters = count($code_char_range);
        if(function_exists('bcpow')){
            return bcpow($count_characters, $this->default_code_length);
        }else{
            return pow($count_characters, $this->default_code_length);
        }

    }

    public function CodeTypes(){

        $CodeTypes[1]['code_name'] = '[A-Z]';
        $CodeTypes[2]['code_name'] = '[a-z]';
        $CodeTypes[3]['code_name'] = '[A-Z,a-z]';
        $CodeTypes[4]['code_name'] = '[0-9]';
        $CodeTypes[5]['code_name'] = '[A-Z,0-9]';
        $CodeTypes[6]['code_name'] = '[a-z,0-9]';
        $CodeTypes[7]['code_name'] = '[A-Z,a-z,0-9]';
        $CodeTypes[8]['code_name'] = '[A-Z,a-z,0-9,-_]';

        $CodeTypes[1]['code_description'] = 'Alphabetical -> Simple:Capital letters';
        $CodeTypes[2]['code_description'] = 'Alphabetical -> Simple:Small letters';
        $CodeTypes[3]['code_description'] = 'Alphabetical -> Combi:Capital and small letters';
        $CodeTypes[4]['code_description'] = 'Numerical -> Simple';
        $CodeTypes[5]['code_description'] = 'Alphabetical and Numerical -> Simple:Capital letters(Megaupload.com)';
        $CodeTypes[6]['code_description'] = 'Alphabetical and Numerical -> Simple:Small letters';
        $CodeTypes[7]['code_description'] = 'Alphabetical and Numerical -> Combi:Capital and small letters';
        $CodeTypes[8]['code_description'] = 'Alphabetical and Numerical -> Combi:Capital and small letters plus special chars(Youtube.com)';

        $CodeTypes[1]['code_generated_time'] = microtime(TRUE);
        $CodeTypes[2]['code_generated_time'] = microtime(TRUE);
        $CodeTypes[3]['code_generated_time'] = microtime(TRUE);
        $CodeTypes[4]['code_generated_time'] = microtime(TRUE);
        $CodeTypes[5]['code_generated_time'] = microtime(TRUE);
        $CodeTypes[6]['code_generated_time'] = microtime(TRUE);
        $CodeTypes[7]['code_generated_time'] = microtime(TRUE);
        $CodeTypes[8]['code_generated_time'] = microtime(TRUE);

        $CodeTypes[1]['code_char_range'] = range('A','Z');
        $CodeTypes[2]['code_char_range'] = range('a','z');
        $CodeTypes[3]['code_char_range'] = array_merge(range('A','Z'), range('a','z'));
        $CodeTypes[4]['code_char_range'] = range(0,9);
        $CodeTypes[5]['code_char_range'] = array_merge(range('A','Z'), range(0,9));
        $CodeTypes[6]['code_char_range'] = array_merge(range('a','z'), range(0,9));
        $CodeTypes[7]['code_char_range'] = array_merge(range('A','Z'), range('a','z'), range(0,9));
        $CodeTypes[8]['code_char_range'] = array_merge(range('A','Z'), range('a','z'), range(0,9),array('-','_'));

        $CodeTypes[1]['code_char_count'] = count($CodeTypes[1]['code_char_range']);
        $CodeTypes[2]['code_char_count'] = count($CodeTypes[2]['code_char_range']);
        $CodeTypes[3]['code_char_count'] = count($CodeTypes[3]['code_char_range']);
        $CodeTypes[4]['code_char_count'] = count($CodeTypes[4]['code_char_range']);
        $CodeTypes[5]['code_char_count'] = count($CodeTypes[5]['code_char_range']);
        $CodeTypes[6]['code_char_count'] = count($CodeTypes[6]['code_char_range']);
        $CodeTypes[7]['code_char_count'] = count($CodeTypes[7]['code_char_range']);
        $CodeTypes[8]['code_char_count'] = count($CodeTypes[8]['code_char_range']);

        $CodeTypes[1]['code_max_number'] = $this->CodeCountRange($CodeTypes[1]['code_char_range']);
        $CodeTypes[2]['code_max_number'] = $this->CodeCountRange($CodeTypes[2]['code_char_range']);
        $CodeTypes[3]['code_max_number'] = $this->CodeCountRange($CodeTypes[3]['code_char_range']);
        $CodeTypes[4]['code_max_number'] = $this->CodeCountRange($CodeTypes[4]['code_char_range']);
        $CodeTypes[5]['code_max_number'] = $this->CodeCountRange($CodeTypes[5]['code_char_range']);
        $CodeTypes[6]['code_max_number'] = $this->CodeCountRange($CodeTypes[6]['code_char_range']);
        $CodeTypes[7]['code_max_number'] = $this->CodeCountRange($CodeTypes[7]['code_char_range']);
        $CodeTypes[8]['code_max_number'] = $this->CodeCountRange($CodeTypes[8]['code_char_range']);

        $this->CodeType = $CodeTypes[$this->default_code_type];
        return $CodeTypes;
    }

    public function CodeInput($CodeInput=''){
        if(!empty($CodeInput)){
            $this->run_default_code = FALSE;
            $this->CodeInputOld = $CodeInput;
        }else{
            $this->run_random_code = FALSE;
        }
    }

    public function Search($Value){
        $code_char_range = $this->CodeType['code_char_range'];
        foreach($code_char_range AS $KeyNumber=>$KeyString){
            if("$KeyString"=="$Value"){
                return $KeyNumber;
                break;
            }

        }
    }

    public function CodeCreateNext(){

    $code_char_range = $this->CodeType['code_char_range'];
    $code_char_range_start = reset($code_char_range);
    $code_char_range_end = end($code_char_range);

    $code_str_split = str_split($this->CodeInputOld);

    // Starts a search for the next incrementable character, ie, other than code_char_range_end
    // Note that it starts from the last character for the first character
        for($i = count($code_str_split)-1;$i>-1;$i--){
            if("$code_str_split[$i]" == "$code_char_range_end"){
                if($i==0){
                // If it is equal to code_char_range_end and is the first character, then it increases the length and zera
                $code_str_split = array_fill(0,count($code_str_split) + 1,"$code_char_range_start");
                return $code_str_split;
                }else{
                    $n = $i-1;
                    $code_str_pos = $this->Search("$code_str_split[$n]")+1;
                    if("$code_str_split[$n]" != "$code_char_range_end"){
                    // If the previous character is different from code_char_range_end, it increments it and clears the current and subsequent characters
                    // If the previous character is the first one, it also works, because it increments it and zeroes the others
                    if(empty($code_char_range[$code_str_pos])){
                        $code_str_split[$n] = settype($code_char_range[$code_str_pos],'string');
                    }else{
                        $code_str_split[$n] = $code_char_range[$code_str_pos];
                    }
                        for($j = $i; $j < count($code_str_split); $j++){
                            $code_str_split[$j] = $code_char_range_start;
                        }
                    return $code_str_split;
                    }
                }
            }else{
                // calculates the next character, ie, increments the current character
                $code_str_pos = $this->Search("$code_str_split[$i]")+1;
                if(empty($code_char_range[$code_str_pos])){
                    $code_str_split[$i] = settype($code_char_range[$code_str_pos],'string');
                }else{
                    $code_str_split[$i] = $code_char_range[$code_str_pos];
                }
                if($i == 0){
                    // If it is the first character, it means that the others are code_char_range_end
                    // That is, he zeroes them
                    $novo_array = array_fill(0,count($code_str_split),"$code_char_range_start");
                    $novo_array[0] = $code_str_split[$i];
                    $code_str_split = $novo_array;
                }
            return $code_str_split;
            }
        }
    }

    public function CodeCreate(){

        $code_char_count = $this->CodeType['code_char_count'];
        $code_char_range = $this->CodeType['code_char_range'];
        $code_char_range_start = reset($code_char_range);

        $this->code_char_base = [];
        if($this->run_default_code){
            for($n=1;$this->default_code_length>=$n;$n++){
                if($this->run_random_code){
                    $this->code_char_base[] = $code_char_range[mt_rand(0,($code_char_count-1))];
                }else{
                    $this->code_char_base[] = $code_char_range_start;
                }
            }
        }else{
            $this->code_char_base = $this->CodeCreateNext();
        }
    }

    public function CodeCountNumber() {
        $code_char_count = $this->CodeType['code_char_count'];
        $code_char_range = $this->CodeType['code_char_range'];

        $character_keys = array_flip($code_char_range);
        $code_characters = $this->code_char_base;

        $number = 0;
        for ($i = 0; $i < count($code_characters); $i++) {
                $number = $number * $code_char_count + $character_keys[$code_characters[$i]];
        }
        $this->code_pos_num = ($number+1);
    }

    public function CodeArray(){
        $code_base = implode($this->code_char_base);
    if($this->default_code_length==strlen($code_base)){
            return array(
                    'code_base'=>$code_base,
                    'code_base_md5'=>md5($code_base),
                    'code_base_sha1'=>sha1($code_base),
                    'code_base64_encode'=>base64_encode($code_base),
                    'code_max_number'=>$this->CodeType['code_max_number'],
                    'code_pos_num'=>$this->code_pos_num,
                    'code_time'=>$this->CodeType['code_generated_time'],
                    'code_message'=>'is_acurrate',
                    'code_name'=>$this->CodeType['code_name'],
                    'code_description'=>$this->CodeType['code_description'],
                    'code_type'=>$this->default_code_type,
                    'code_max_type'=>$this->code_max_type,
                    'code_length'=>$this->default_code_length
                    );
        }elseif($this->default_code_length<strlen($code_base)){
            return array(
                        'code_base'=>$code_base,
                        'code_base_md5'=>md5($code_base),
                        'code_base_sha1'=>sha1($code_base),
                        'code_base64_encode'=>base64_encode($code_base),
                        'code_max_number'=>$this->CodeType['code_max_number'],
                        'code_pos_num'=>$this->code_pos_num,
                        'code_time'=>$this->CodeType['code_generated_time'],
                        'code_message'=>'is_upper_or_full',
                        'code_name'=>$this->CodeType['code_name'],
                        'code_description'=>$this->CodeType['code_description'],
                        'code_type'=>$this->default_code_type,
                        'code_max_type'=>$this->code_max_type,
                        'code_length'=>$this->default_code_length
                        );
        }else{
            return array(
                        'code_base'=>$code_base,
                        'code_base_md5'=>md5($code_base),
                        'code_base_sha1'=>sha1($code_base),
                        'code_base64_encode'=>base64_encode($code_base),
                        'code_max_number'=>$this->CodeType['code_max_number'],
                        'code_pos_num'=>$this->code_pos_num,
                        'code_time'=>$this->CodeType['code_generated_time'],
                        'code_message'=>'is_lower',
                        'code_name'=>$this->CodeType['code_name'],
                        'code_description'=>$this->CodeType['code_description'],
                        'code_type'=>$this->default_code_type,
                        'code_max_type'=>$this->code_max_type,
                        'code_length'=>$this->default_code_length
                        );
        }
    }

    public function Generate_String(){
        $this->CodeTypes();
        $this->CodeCreate();
        $this->CodeCountNumber();
        return $this->CodeArray();
    }

    public function Generate_ID($GenerateID){
        is_numeric($GenerateID) OR die('The ID must be numberic!');
        $this->CodeTypes();
        $code_char_count = $this->CodeType['code_char_count'];
        $code_char_range = $this->CodeType['code_char_range'];

        $one = 1;
        if($GenerateID>$this->CodeType['code_max_number']){
            //Perform reset
            $code_id = ($one - $one);
        }else{
            $code_id = ($GenerateID - $one);
        }
        for($length=($this->default_code_length - $one);$length>=0;$length--){
            if(function_exists('bcpow')){
                $bcpow = bcpow($code_char_count, $length);
                $possition = floor($code_id / $bcpow);
                $code_id = $code_id - ($possition * $bcpow);
            }else{
                $pow = pow($code_char_count, $length);
                $possition = floor($code_id / $pow);
                $code_id = $code_id - ($possition * $pow);
            }

            $this->code_char_base[$length] = $code_char_range[$possition];
        }
        $this->CodeCountNumber();
        return $this->CodeArray();
    }
}
?>
</code>```

How to use it :

```<code><?php
include('CANG.php');
$CANG = new CANG;
$CANG->SetType(5);
$CANG->CodeInput('Z');
$return = $CANG->Generate_String();
print_r($return);
?>
</code>```

答:
So i found the error and the issue its gone forever.
I have removed the each line that includes :

```<code>if(empty($code_char_range[$code_str_pos])){
     $code_str_split[$i] = settype($code_char_range[$code_str_pos],'string');
 }else{
    $code_str_split[$i] = $code_char_range[$code_str_pos];
 }
</code>```

And here is the tested CODE :

```<code>    public $default_code_length = 1;
    public $default_code_type = 1;
    public $run_default_code = TRUE;
    public $run_random_code = TRUE;
    public $code_max_type = 8;

    public function __construct(){
        /*
        Nothing to do here but if you need to use it with CI must write :
        class CANG extends CI_Library {}
        and remove the double back slash below
        */
        //parent::__construct();
    }

    public function SetLength($SetLength=FALSE){
        if(is_numeric($SetLength)){
            $this->default_code_length = $SetLength;
        }
    }

    public function SetType($SetType=FALSE){
        if(is_numeric($SetType) AND $this->code_max_type>=$SetType){
            $this->default_code_type = $SetType;
        }
    }

    public function CodeCountRange($code_char_range=[]){
        $count_characters = count($code_char_range);
        if(function_exists('bcpow')){
            return bcpow($count_characters, $this->default_code_length);
        }else{
            return pow($count_characters, $this->default_code_length);
        }

    }

    public function CodeTypes(){

        $CodeTypes[1]['code_name'] = '[A-Z]';
        $CodeTypes[2]['code_name'] = '[a-z]';
        $CodeTypes[3]['code_name'] = '[A-Z,a-z]';
        $CodeTypes[4]['code_name'] = '[0-9]';
        $CodeTypes[5]['code_name'] = '[A-Z,0-9]';
        $CodeTypes[6]['code_name'] = '[a-z,0-9]';
        $CodeTypes[7]['code_name'] = '[A-Z,a-z,0-9]';
        $CodeTypes[8]['code_name'] = '[A-Z,a-z,0-9,-_]';

        $CodeTypes[1]['code_description'] = 'Alphabetical -> Simple:Capital letters';
        $CodeTypes[2]['code_description'] = 'Alphabetical -> Simple:Small letters';
        $CodeTypes[3]['code_description'] = 'Alphabetical -> Combi:Capital and small letters';
        $CodeTypes[4]['code_description'] = 'Numerical -> Simple';
        $CodeTypes[5]['code_description'] = 'Alphabetical and Numerical -> Simple:Capital letters(Megaupload.com)';
        $CodeTypes[6]['code_description'] = 'Alphabetical and Numerical -> Simple:Small letters';
        $CodeTypes[7]['code_description'] = 'Alphabetical and Numerical -> Combi:Capital and small letters';
        $CodeTypes[8]['code_description'] = 'Alphabetical and Numerical -> Combi:Capital and small letters plus special chars(Youtube.com)';

        $CodeTypes[1]['code_generated_time'] = microtime(TRUE);
        $CodeTypes[2]['code_generated_time'] = microtime(TRUE);
        $CodeTypes[3]['code_generated_time'] = microtime(TRUE);
        $CodeTypes[4]['code_generated_time'] = microtime(TRUE);
        $CodeTypes[5]['code_generated_time'] = microtime(TRUE);
        $CodeTypes[6]['code_generated_time'] = microtime(TRUE);
        $CodeTypes[7]['code_generated_time'] = microtime(TRUE);
        $CodeTypes[8]['code_generated_time'] = microtime(TRUE);

        $CodeTypes[1]['code_char_range'] = range('A','Z');
        $CodeTypes[2]['code_char_range'] = range('a','z');
        $CodeTypes[3]['code_char_range'] = array_merge(range('A','Z'), range('a','z'));
        $CodeTypes[4]['code_char_range'] = range(0,9);
        $CodeTypes[5]['code_char_range'] = array_merge(range('A','Z'), range(0,9));
        $CodeTypes[6]['code_char_range'] = array_merge(range('a','z'), range(0,9));
        $CodeTypes[7]['code_char_range'] = array_merge(range('A','Z'), range('a','z'), range(0,9));
        $CodeTypes[8]['code_char_range'] = array_merge(range('A','Z'), range('a','z'), range(0,9),array('-','_'));

        $CodeTypes[1]['code_char_count'] = count($CodeTypes[1]['code_char_range']);
        $CodeTypes[2]['code_char_count'] = count($CodeTypes[2]['code_char_range']);
        $CodeTypes[3]['code_char_count'] = count($CodeTypes[3]['code_char_range']);
        $CodeTypes[4]['code_char_count'] = count($CodeTypes[4]['code_char_range']);
        $CodeTypes[5]['code_char_count'] = count($CodeTypes[5]['code_char_range']);
        $CodeTypes[6]['code_char_count'] = count($CodeTypes[6]['code_char_range']);
        $CodeTypes[7]['code_char_count'] = count($CodeTypes[7]['code_char_range']);
        $CodeTypes[8]['code_char_count'] = count($CodeTypes[8]['code_char_range']);

        $CodeTypes[1]['code_max_number'] = $this->CodeCountRange($CodeTypes[1]['code_char_range']);
        $CodeTypes[2]['code_max_number'] = $this->CodeCountRange($CodeTypes[2]['code_char_range']);
        $CodeTypes[3]['code_max_number'] = $this->CodeCountRange($CodeTypes[3]['code_char_range']);
        $CodeTypes[4]['code_max_number'] = $this->CodeCountRange($CodeTypes[4]['code_char_range']);
        $CodeTypes[5]['code_max_number'] = $this->CodeCountRange($CodeTypes[5]['code_char_range']);
        $CodeTypes[6]['code_max_number'] = $this->CodeCountRange($CodeTypes[6]['code_char_range']);
        $CodeTypes[7]['code_max_number'] = $this->CodeCountRange($CodeTypes[7]['code_char_range']);
        $CodeTypes[8]['code_max_number'] = $this->CodeCountRange($CodeTypes[8]['code_char_range']);

        $this->CodeType = $CodeTypes[$this->default_code_type];
        return $CodeTypes;
    }

    public function CodeInput($CodeInput=''){
        if(!empty($CodeInput)){
            $this->run_default_code = FALSE;
            $this->CodeInputOld = $CodeInput;
        }else{
            $this->run_random_code = FALSE;
        }
    }

    public function Search($Value){
        $code_char_range = $this->CodeType['code_char_range'];
        foreach($code_char_range AS $KeyNumber=>$KeyString){
            if("$KeyString"=="$Value"){
                return $KeyNumber;
                break;
            }

        }
    }

    public function CodeCreateNext(){

    $code_char_range = $this->CodeType['code_char_range'];
    $code_char_range_start = reset($code_char_range);
    $code_char_range_end = end($code_char_range);

    $code_str_split = str_split($this->CodeInputOld);

    // Starts a search for the next incrementable character, ie, other than code_char_range_end
    // Note that it starts from the last character for the first character
        for($i = count($code_str_split)-1;$i>-1;$i--){
            if("$code_str_split[$i]" == "$code_char_range_end"){
                if($i==0){
                // If it is equal to code_char_range_end and is the first character, then it increases the length and zera
                $code_str_split = array_fill(0,count($code_str_split) + 1,"$code_char_range_start");
                return $code_str_split;
                }else{
                    $n = $i-1;
                    $code_str_pos = $this->Search("$code_str_split[$n]")+1;
                    if("$code_str_split[$n]" != "$code_char_range_end"){
                    // If the previous character is different from code_char_range_end, it increments it and clears the current and subsequent characters
                    // If the previous character is the first one, it also works, because it increments it and zeroes the others
                    $code_str_split[$n] = $code_char_range[$code_str_pos];

                        for($j = $i; $j < count($code_str_split); $j++){
                            $code_str_split[$j] = $code_char_range_start;
                        }
                    return $code_str_split;
                    }
                }
            }else{
                // calculates the next character, ie, increments the current character
                $code_str_pos = $this->Search("$code_str_split[$i]")+1;
                $code_str_split[$i] = $code_char_range[$code_str_pos];
                if($i == 0){
                    // If it is the first character, it means that the others are code_char_range_end
                    // That is, he zeroes them
                    $novo_array = array_fill(0,count($code_str_split),"$code_char_range_start");
                    $novo_array[0] = $code_str_split[$i];
                    $code_str_split = $novo_array;
                }
            return $code_str_split;
            }
        }
    }

    public function CodeCreate(){

        $code_char_count = $this->CodeType['code_char_count'];
        $code_char_range = $this->CodeType['code_char_range'];
        $code_char_range_start = reset($code_char_range);

        $this->code_char_base = [];
        if($this->run_default_code){
            for($n=1;$this->default_code_length>=$n;$n++){
                if($this->run_random_code){
                    $this->code_char_base[] = $code_char_range[mt_rand(0,($code_char_count-1))];
                }else{
                    $this->code_char_base[] = $code_char_range_start;
                }
            }
        }else{
            $this->code_char_base = $this->CodeCreateNext();
        }
    }

    public function CodeCountNumber() {
        $code_char_count = $this->CodeType['code_char_count'];
        $code_char_range = $this->CodeType['code_char_range'];

        $character_keys = array_flip($code_char_range);
        $code_characters = $this->code_char_base;

        $number = 0;
        for ($i = 0; $i < count($code_characters); $i++) {
                $number = $number * $code_char_count + $character_keys[$code_characters[$i]];
        }
        $this->code_pos_num = ($number+1);
    }

    public function CodeArray(){
        $code_base = implode($this->code_char_base);
    if($this->default_code_length==strlen($code_base)){
            return array(
                    'code_base'=>$code_base,
                    'code_base_md5'=>md5($code_base),
                    'code_base_sha1'=>sha1($code_base),
                    'code_base64_encode'=>base64_encode($code_base),
                    'code_max_number'=>$this->CodeType['code_max_number'],
                    'code_pos_num'=>$this->code_pos_num,
                    'code_time'=>$this->CodeType['code_generated_time'],
                    'code_message'=>'is_acurrate',
                    'code_name'=>$this->CodeType['code_name'],
                    'code_description'=>$this->CodeType['code_description'],
                    'code_type'=>$this->default_code_type,
                    'code_max_type'=>$this->code_max_type,
                    'code_length'=>$this->default_code_length
                    );
        }elseif($this->default_code_length<strlen($code_base)){
            return array(
                        'code_base'=>$code_base,
                        'code_base_md5'=>md5($code_base),
                        'code_base_sha1'=>sha1($code_base),
                        'code_base64_encode'=>base64_encode($code_base),
                        'code_max_number'=>$this->CodeType['code_max_number'],
                        'code_pos_num'=>$this->code_pos_num,
                        'code_time'=>$this->CodeType['code_generated_time'],
                        'code_message'=>'is_upper_or_full',
                        'code_name'=>$this->CodeType['code_name'],
                        'code_description'=>$this->CodeType['code_description'],
                        'code_type'=>$this->default_code_type,
                        'code_max_type'=>$this->code_max_type,
                        'code_length'=>$this->default_code_length
                        );
        }else{
            return array(
                        'code_base'=>$code_base,
                        'code_base_md5'=>md5($code_base),
                        'code_base_sha1'=>sha1($code_base),
                        'code_base64_encode'=>base64_encode($code_base),
                        'code_max_number'=>$this->CodeType['code_max_number'],
                        'code_pos_num'=>$this->code_pos_num,
                        'code_time'=>$this->CodeType['code_generated_time'],
                        'code_message'=>'is_lower',
                        'code_name'=>$this->CodeType['code_name'],
                        'code_description'=>$this->CodeType['code_description'],
                        'code_type'=>$this->default_code_type,
                        'code_max_type'=>$this->code_max_type,
                        'code_length'=>$this->default_code_length
                        );
        }
    }

    public function Generate_String(){
        $this->CodeTypes();
        $this->CodeCreate();
        $this->CodeCountNumber();
        return $this->CodeArray();
    }

    public function Generate_ID($GenerateID){
        is_numeric($GenerateID) OR die('The ID must be numberic!');
        $this->CodeTypes();
        $code_char_count = $this->CodeType['code_char_count'];
        $code_char_range = $this->CodeType['code_char_range'];

        $one = 1;
        if($GenerateID>$this->CodeType['code_max_number']){
            //Perform reset
            $code_id = ($one - $one);
        }else{
            $code_id = ($GenerateID - $one);
        }
        for($length=($this->default_code_length - $one);$length>=0;$length--){
            if(function_exists('bcpow')){
                $bcpow = bcpow($code_char_count, $length);
                $possition = floor($code_id / $bcpow);
                $code_id = $code_id - ($possition * $bcpow);
            }else{
                $pow = pow($code_char_count, $length);
                $possition = floor($code_id / $pow);
                $code_id = $code_id - ($possition * $pow);
            }

            $this->code_char_base[$length] = $code_char_range[$possition];
        }
        $this->CodeCountNumber();
        return $this->CodeArray();
    }
}
?>
</code>```

Title: php CANG does not using value 0

Body:
Hi there i have a little issue with my CANG(Complex Alpha Numeric Generator) in php,

the generator is not inserting the number 0 into string.

This is from my DB MySQL

Example :

AAAAACPZ next code is -> AAAAACP1

but it should be AAAAACP0 and after AAAAACP1

Can somebody help me please to solve this issue?

Search for CANG.php and have look on my CANG class at here.

I remember once i have done this in the previous version,

but after some time i decide it to delete all the codes

and later on i build new versions.

If anyone come up with something let me know.

Thanks in advance

A little explanation :

All the generation of strings depends on the settings provided.

For example a have range('A','Z') and range(0,9)

so after every Z should be number zero -> 0 and not number 1.

<?php
class CANG {

    public $default_code_length = 1;
    public $default_code_type = 1;
    public $run_default_code = TRUE;
    public $run_random_code = TRUE;
    public $code_max_type = 8;

    public function __construct(){
        /*
        Nothing to do here but if you need to use it with CI must write :
        class CANG extends CI_Library {}
        and remove the double back slash below
        */
        //parent::__construct();
    }

    public function SetLength($SetLength=FALSE){
        if(is_numeric($SetLength)){
            $this->default_code_length = $SetLength;
        }
    }

    public function SetType($SetType=FALSE){
        if(is_numeric($SetType) AND $this->code_max_type>=$SetType){
            $this->default_code_type = $SetType;
        }
    }

    public function CodeCountRange($code_char_range=[]){
        $count_characters = count($code_char_range);
        if(function_exists('bcpow')){
            return bcpow($count_characters, $this->default_code_length);
        }else{
            return pow($count_characters, $this->default_code_length);
        }

    }

    public function CodeTypes(){

        $CodeTypes[1]['code_name'] = '[A-Z]';
        $CodeTypes[2]['code_name'] = '[a-z]';
        $CodeTypes[3]['code_name'] = '[A-Z,a-z]';
        $CodeTypes[4]['code_name'] = '[0-9]';
        $CodeTypes[5]['code_name'] = '[A-Z,0-9]';
        $CodeTypes[6]['code_name'] = '[a-z,0-9]';
        $CodeTypes[7]['code_name'] = '[A-Z,a-z,0-9]';
        $CodeTypes[8]['code_name'] = '[A-Z,a-z,0-9,-_]';

        $CodeTypes[1]['code_description'] = 'Alphabetical -> Simple:Capital letters';
        $CodeTypes[2]['code_description'] = 'Alphabetical -> Simple:Small letters';
        $CodeTypes[3]['code_description'] = 'Alphabetical -> Combi:Capital and small letters';
        $CodeTypes[4]['code_description'] = 'Numerical -> Simple';
        $CodeTypes[5]['code_description'] = 'Alphabetical and Numerical -> Simple:Capital letters(Megaupload.com)';
        $CodeTypes[6]['code_description'] = 'Alphabetical and Numerical -> Simple:Small letters';
        $CodeTypes[7]['code_description'] = 'Alphabetical and Numerical -> Combi:Capital and small letters';
        $CodeTypes[8]['code_description'] = 'Alphabetical and Numerical -> Combi:Capital and small letters plus special chars(Youtube.com)';

        $CodeTypes[1]['code_generated_time'] = microtime(TRUE);
        $CodeTypes[2]['code_generated_time'] = microtime(TRUE);
        $CodeTypes[3]['code_generated_time'] = microtime(TRUE);
        $CodeTypes[4]['code_generated_time'] = microtime(TRUE);
        $CodeTypes[5]['code_generated_time'] = microtime(TRUE);
        $CodeTypes[6]['code_generated_time'] = microtime(TRUE);
        $CodeTypes[7]['code_generated_time'] = microtime(TRUE);
        $CodeTypes[8]['code_generated_time'] = microtime(TRUE);

        $CodeTypes[1]['code_char_range'] = range('A','Z');
        $CodeTypes[2]['code_char_range'] = range('a','z');
        $CodeTypes[3]['code_char_range'] = array_merge(range('A','Z'), range('a','z'));
        $CodeTypes[4]['code_char_range'] = range(0,9);
        $CodeTypes[5]['code_char_range'] = array_merge(range('A','Z'), range(0,9));
        $CodeTypes[6]['code_char_range'] = array_merge(range('a','z'), range(0,9));
        $CodeTypes[7]['code_char_range'] = array_merge(range('A','Z'), range('a','z'), range(0,9));
        $CodeTypes[8]['code_char_range'] = array_merge(range('A','Z'), range('a','z'), range(0,9),array('-','_'));

        $CodeTypes[1]['code_char_count'] = count($CodeTypes[1]['code_char_range']);
        $CodeTypes[2]['code_char_count'] = count($CodeTypes[2]['code_char_range']);
        $CodeTypes[3]['code_char_count'] = count($CodeTypes[3]['code_char_range']);
        $CodeTypes[4]['code_char_count'] = count($CodeTypes[4]['code_char_range']);
        $CodeTypes[5]['code_char_count'] = count($CodeTypes[5]['code_char_range']);
        $CodeTypes[6]['code_char_count'] = count($CodeTypes[6]['code_char_range']);
        $CodeTypes[7]['code_char_count'] = count($CodeTypes[7]['code_char_range']);
        $CodeTypes[8]['code_char_count'] = count($CodeTypes[8]['code_char_range']);

        $CodeTypes[1]['code_max_number'] = $this->CodeCountRange($CodeTypes[1]['code_char_range']);
        $CodeTypes[2]['code_max_number'] = $this->CodeCountRange($CodeTypes[2]['code_char_range']);
        $CodeTypes[3]['code_max_number'] = $this->CodeCountRange($CodeTypes[3]['code_char_range']);
        $CodeTypes[4]['code_max_number'] = $this->CodeCountRange($CodeTypes[4]['code_char_range']);
        $CodeTypes[5]['code_max_number'] = $this->CodeCountRange($CodeTypes[5]['code_char_range']);
        $CodeTypes[6]['code_max_number'] = $this->CodeCountRange($CodeTypes[6]['code_char_range']);
        $CodeTypes[7]['code_max_number'] = $this->CodeCountRange($CodeTypes[7]['code_char_range']);
        $CodeTypes[8]['code_max_number'] = $this->CodeCountRange($CodeTypes[8]['code_char_range']);

        $this->CodeType = $CodeTypes[$this->default_code_type];
        return $CodeTypes;
    }

    public function CodeInput($CodeInput=''){
        if(!empty($CodeInput)){
            $this->run_default_code = FALSE;
            $this->CodeInputOld = $CodeInput;
        }else{
            $this->run_random_code = FALSE;
        }
    }

    public function Search($Value){
        $code_char_range = $this->CodeType['code_char_range'];
        foreach($code_char_range AS $KeyNumber=>$KeyString){
            if("$KeyString"=="$Value"){
                return $KeyNumber;
                break;
            }

        }
    }

    public function CodeCreateNext(){

    $code_char_range = $this->CodeType['code_char_range'];
    $code_char_range_start = reset($code_char_range);
    $code_char_range_end = end($code_char_range);

    $code_str_split = str_split($this->CodeInputOld);

    // Starts a search for the next incrementable character, ie, other than code_char_range_end
    // Note that it starts from the last character for the first character
        for($i = count($code_str_split)-1;$i>-1;$i--){
            if("$code_str_split[$i]" == "$code_char_range_end"){
                if($i==0){
                // If it is equal to code_char_range_end and is the first character, then it increases the length and zera
                $code_str_split = array_fill(0,count($code_str_split) + 1,"$code_char_range_start");
                return $code_str_split;
                }else{
                    $n = $i-1;
                    $code_str_pos = $this->Search("$code_str_split[$n]")+1;
                    if("$code_str_split[$n]" != "$code_char_range_end"){
                    // If the previous character is different from code_char_range_end, it increments it and clears the current and subsequent characters
                    // If the previous character is the first one, it also works, because it increments it and zeroes the others
                    if(empty($code_char_range[$code_str_pos])){
                        $code_str_split[$n] = settype($code_char_range[$code_str_pos],'string');
                    }else{
                        $code_str_split[$n] = $code_char_range[$code_str_pos];
                    }
                        for($j = $i; $j < count($code_str_split); $j++){
                            $code_str_split[$j] = $code_char_range_start;
                        }
                    return $code_str_split;
                    }
                }
            }else{
                // calculates the next character, ie, increments the current character
                $code_str_pos = $this->Search("$code_str_split[$i]")+1;
                if(empty($code_char_range[$code_str_pos])){
                    $code_str_split[$i] = settype($code_char_range[$code_str_pos],'string');
                }else{
                    $code_str_split[$i] = $code_char_range[$code_str_pos];
                }
                if($i == 0){
                    // If it is the first character, it means that the others are code_char_range_end
                    // That is, he zeroes them
                    $novo_array = array_fill(0,count($code_str_split),"$code_char_range_start");
                    $novo_array[0] = $code_str_split[$i];
                    $code_str_split = $novo_array;
                }
            return $code_str_split;
            }
        }
    }

    public function CodeCreate(){

        $code_char_count = $this->CodeType['code_char_count'];
        $code_char_range = $this->CodeType['code_char_range'];
        $code_char_range_start = reset($code_char_range);

        $this->code_char_base = [];
        if($this->run_default_code){
            for($n=1;$this->default_code_length>=$n;$n++){
                if($this->run_random_code){
                    $this->code_char_base[] = $code_char_range[mt_rand(0,($code_char_count-1))];
                }else{
                    $this->code_char_base[] = $code_char_range_start;
                }
            }
        }else{
            $this->code_char_base = $this->CodeCreateNext();
        }
    }

    public function CodeCountNumber() {
        $code_char_count = $this->CodeType['code_char_count'];
        $code_char_range = $this->CodeType['code_char_range'];

        $character_keys = array_flip($code_char_range);
        $code_characters = $this->code_char_base;

        $number = 0;
        for ($i = 0; $i < count($code_characters); $i++) {
                $number = $number * $code_char_count + $character_keys[$code_characters[$i]];
        }
        $this->code_pos_num = ($number+1);
    }

    public function CodeArray(){
        $code_base = implode($this->code_char_base);
    if($this->default_code_length==strlen($code_base)){
            return array(
                    'code_base'=>$code_base,
                    'code_base_md5'=>md5($code_base),
                    'code_base_sha1'=>sha1($code_base),
                    'code_base64_encode'=>base64_encode($code_base),
                    'code_max_number'=>$this->CodeType['code_max_number'],
                    'code_pos_num'=>$this->code_pos_num,
                    'code_time'=>$this->CodeType['code_generated_time'],
                    'code_message'=>'is_acurrate',
                    'code_name'=>$this->CodeType['code_name'],
                    'code_description'=>$this->CodeType['code_description'],
                    'code_type'=>$this->default_code_type,
                    'code_max_type'=>$this->code_max_type,
                    'code_length'=>$this->default_code_length
                    );
        }elseif($this->default_code_length<strlen($code_base)){
            return array(
                        'code_base'=>$code_base,
                        'code_base_md5'=>md5($code_base),
                        'code_base_sha1'=>sha1($code_base),
                        'code_base64_encode'=>base64_encode($code_base),
                        'code_max_number'=>$this->CodeType['code_max_number'],
                        'code_pos_num'=>$this->code_pos_num,
                        'code_time'=>$this->CodeType['code_generated_time'],
                        'code_message'=>'is_upper_or_full',
                        'code_name'=>$this->CodeType['code_name'],
                        'code_description'=>$this->CodeType['code_description'],
                        'code_type'=>$this->default_code_type,
                        'code_max_type'=>$this->code_max_type,
                        'code_length'=>$this->default_code_length
                        );
        }else{
            return array(
                        'code_base'=>$code_base,
                        'code_base_md5'=>md5($code_base),
                        'code_base_sha1'=>sha1($code_base),
                        'code_base64_encode'=>base64_encode($code_base),
                        'code_max_number'=>$this->CodeType['code_max_number'],
                        'code_pos_num'=>$this->code_pos_num,
                        'code_time'=>$this->CodeType['code_generated_time'],
                        'code_message'=>'is_lower',
                        'code_name'=>$this->CodeType['code_name'],
                        'code_description'=>$this->CodeType['code_description'],
                        'code_type'=>$this->default_code_type,
                        'code_max_type'=>$this->code_max_type,
                        'code_length'=>$this->default_code_length
                        );
        }
    }

    public function Generate_String(){
        $this->CodeTypes();
        $this->CodeCreate();
        $this->CodeCountNumber();
        return $this->CodeArray();
    }

    public function Generate_ID($GenerateID){
        is_numeric($GenerateID) OR die('The ID must be numberic!');
        $this->CodeTypes();
        $code_char_count = $this->CodeType['code_char_count'];
        $code_char_range = $this->CodeType['code_char_range'];

        $one = 1;
        if($GenerateID>$this->CodeType['code_max_number']){
            //Perform reset
            $code_id = ($one - $one);
        }else{
            $code_id = ($GenerateID - $one);
        }
        for($length=($this->default_code_length - $one);$length>=0;$length--){
            if(function_exists('bcpow')){
                $bcpow = bcpow($code_char_count, $length);
                $possition = floor($code_id / $bcpow);
                $code_id = $code_id - ($possition * $bcpow);
            }else{
                $pow = pow($code_char_count, $length);
                $possition = floor($code_id / $pow);
                $code_id = $code_id - ($possition * $pow);
            }

            $this->code_char_base[$length] = $code_char_range[$possition];
        }
        $this->CodeCountNumber();
        return $this->CodeArray();
    }
}
?>

How to use it :

<?php
include('CANG.php');
$CANG = new CANG;
$CANG->SetType(5);
$CANG->CodeInput('Z');
$return = $CANG->Generate_String();
print_r($return);
?>

Body:
So i found the error and the issue its gone forever.
I have removed the each line that includes :

if(empty($code_char_range[$code_str_pos])){
     $code_str_split[$i] = settype($code_char_range[$code_str_pos],'string');
 }else{
    $code_str_split[$i] = $code_char_range[$code_str_pos];
 }

And here is the tested CODE :

    public $default_code_length = 1;
    public $default_code_type = 1;
    public $run_default_code = TRUE;
    public $run_random_code = TRUE;
    public $code_max_type = 8;

    public function __construct(){
        /*
        Nothing to do here but if you need to use it with CI must write :
        class CANG extends CI_Library {}
        and remove the double back slash below
        */
        //parent::__construct();
    }

    public function SetLength($SetLength=FALSE){
        if(is_numeric($SetLength)){
            $this->default_code_length = $SetLength;
        }
    }

    public function SetType($SetType=FALSE){
        if(is_numeric($SetType) AND $this->code_max_type>=$SetType){
            $this->default_code_type = $SetType;
        }
    }

    public function CodeCountRange($code_char_range=[]){
        $count_characters = count($code_char_range);
        if(function_exists('bcpow')){
            return bcpow($count_characters, $this->default_code_length);
        }else{
            return pow($count_characters, $this->default_code_length);
        }

    }

    public function CodeTypes(){

        $CodeTypes[1]['code_name'] = '[A-Z]';
        $CodeTypes[2]['code_name'] = '[a-z]';
        $CodeTypes[3]['code_name'] = '[A-Z,a-z]';
        $CodeTypes[4]['code_name'] = '[0-9]';
        $CodeTypes[5]['code_name'] = '[A-Z,0-9]';
        $CodeTypes[6]['code_name'] = '[a-z,0-9]';
        $CodeTypes[7]['code_name'] = '[A-Z,a-z,0-9]';
        $CodeTypes[8]['code_name'] = '[A-Z,a-z,0-9,-_]';

        $CodeTypes[1]['code_description'] = 'Alphabetical -> Simple:Capital letters';
        $CodeTypes[2]['code_description'] = 'Alphabetical -> Simple:Small letters';
        $CodeTypes[3]['code_description'] = 'Alphabetical -> Combi:Capital and small letters';
        $CodeTypes[4]['code_description'] = 'Numerical -> Simple';
        $CodeTypes[5]['code_description'] = 'Alphabetical and Numerical -> Simple:Capital letters(Megaupload.com)';
        $CodeTypes[6]['code_description'] = 'Alphabetical and Numerical -> Simple:Small letters';
        $CodeTypes[7]['code_description'] = 'Alphabetical and Numerical -> Combi:Capital and small letters';
        $CodeTypes[8]['code_description'] = 'Alphabetical and Numerical -> Combi:Capital and small letters plus special chars(Youtube.com)';

        $CodeTypes[1]['code_generated_time'] = microtime(TRUE);
        $CodeTypes[2]['code_generated_time'] = microtime(TRUE);
        $CodeTypes[3]['code_generated_time'] = microtime(TRUE);
        $CodeTypes[4]['code_generated_time'] = microtime(TRUE);
        $CodeTypes[5]['code_generated_time'] = microtime(TRUE);
        $CodeTypes[6]['code_generated_time'] = microtime(TRUE);
        $CodeTypes[7]['code_generated_time'] = microtime(TRUE);
        $CodeTypes[8]['code_generated_time'] = microtime(TRUE);

        $CodeTypes[1]['code_char_range'] = range('A','Z');
        $CodeTypes[2]['code_char_range'] = range('a','z');
        $CodeTypes[3]['code_char_range'] = array_merge(range('A','Z'), range('a','z'));
        $CodeTypes[4]['code_char_range'] = range(0,9);
        $CodeTypes[5]['code_char_range'] = array_merge(range('A','Z'), range(0,9));
        $CodeTypes[6]['code_char_range'] = array_merge(range('a','z'), range(0,9));
        $CodeTypes[7]['code_char_range'] = array_merge(range('A','Z'), range('a','z'), range(0,9));
        $CodeTypes[8]['code_char_range'] = array_merge(range('A','Z'), range('a','z'), range(0,9),array('-','_'));

        $CodeTypes[1]['code_char_count'] = count($CodeTypes[1]['code_char_range']);
        $CodeTypes[2]['code_char_count'] = count($CodeTypes[2]['code_char_range']);
        $CodeTypes[3]['code_char_count'] = count($CodeTypes[3]['code_char_range']);
        $CodeTypes[4]['code_char_count'] = count($CodeTypes[4]['code_char_range']);
        $CodeTypes[5]['code_char_count'] = count($CodeTypes[5]['code_char_range']);
        $CodeTypes[6]['code_char_count'] = count($CodeTypes[6]['code_char_range']);
        $CodeTypes[7]['code_char_count'] = count($CodeTypes[7]['code_char_range']);
        $CodeTypes[8]['code_char_count'] = count($CodeTypes[8]['code_char_range']);

        $CodeTypes[1]['code_max_number'] = $this->CodeCountRange($CodeTypes[1]['code_char_range']);
        $CodeTypes[2]['code_max_number'] = $this->CodeCountRange($CodeTypes[2]['code_char_range']);
        $CodeTypes[3]['code_max_number'] = $this->CodeCountRange($CodeTypes[3]['code_char_range']);
        $CodeTypes[4]['code_max_number'] = $this->CodeCountRange($CodeTypes[4]['code_char_range']);
        $CodeTypes[5]['code_max_number'] = $this->CodeCountRange($CodeTypes[5]['code_char_range']);
        $CodeTypes[6]['code_max_number'] = $this->CodeCountRange($CodeTypes[6]['code_char_range']);
        $CodeTypes[7]['code_max_number'] = $this->CodeCountRange($CodeTypes[7]['code_char_range']);
        $CodeTypes[8]['code_max_number'] = $this->CodeCountRange($CodeTypes[8]['code_char_range']);

        $this->CodeType = $CodeTypes[$this->default_code_type];
        return $CodeTypes;
    }

    public function CodeInput($CodeInput=''){
        if(!empty($CodeInput)){
            $this->run_default_code = FALSE;
            $this->CodeInputOld = $CodeInput;
        }else{
            $this->run_random_code = FALSE;
        }
    }

    public function Search($Value){
        $code_char_range = $this->CodeType['code_char_range'];
        foreach($code_char_range AS $KeyNumber=>$KeyString){
            if("$KeyString"=="$Value"){
                return $KeyNumber;
                break;
            }

        }
    }

    public function CodeCreateNext(){

    $code_char_range = $this->CodeType['code_char_range'];
    $code_char_range_start = reset($code_char_range);
    $code_char_range_end = end($code_char_range);

    $code_str_split = str_split($this->CodeInputOld);

    // Starts a search for the next incrementable character, ie, other than code_char_range_end
    // Note that it starts from the last character for the first character
        for($i = count($code_str_split)-1;$i>-1;$i--){
            if("$code_str_split[$i]" == "$code_char_range_end"){
                if($i==0){
                // If it is equal to code_char_range_end and is the first character, then it increases the length and zera
                $code_str_split = array_fill(0,count($code_str_split) + 1,"$code_char_range_start");
                return $code_str_split;
                }else{
                    $n = $i-1;
                    $code_str_pos = $this->Search("$code_str_split[$n]")+1;
                    if("$code_str_split[$n]" != "$code_char_range_end"){
                    // If the previous character is different from code_char_range_end, it increments it and clears the current and subsequent characters
                    // If the previous character is the first one, it also works, because it increments it and zeroes the others
                    $code_str_split[$n] = $code_char_range[$code_str_pos];

                        for($j = $i; $j < count($code_str_split); $j++){
                            $code_str_split[$j] = $code_char_range_start;
                        }
                    return $code_str_split;
                    }
                }
            }else{
                // calculates the next character, ie, increments the current character
                $code_str_pos = $this->Search("$code_str_split[$i]")+1;
                $code_str_split[$i] = $code_char_range[$code_str_pos];
                if($i == 0){
                    // If it is the first character, it means that the others are code_char_range_end
                    // That is, he zeroes them
                    $novo_array = array_fill(0,count($code_str_split),"$code_char_range_start");
                    $novo_array[0] = $code_str_split[$i];
                    $code_str_split = $novo_array;
                }
            return $code_str_split;
            }
        }
    }

    public function CodeCreate(){

        $code_char_count = $this->CodeType['code_char_count'];
        $code_char_range = $this->CodeType['code_char_range'];
        $code_char_range_start = reset($code_char_range);

        $this->code_char_base = [];
        if($this->run_default_code){
            for($n=1;$this->default_code_length>=$n;$n++){
                if($this->run_random_code){
                    $this->code_char_base[] = $code_char_range[mt_rand(0,($code_char_count-1))];
                }else{
                    $this->code_char_base[] = $code_char_range_start;
                }
            }
        }else{
            $this->code_char_base = $this->CodeCreateNext();
        }
    }

    public function CodeCountNumber() {
        $code_char_count = $this->CodeType['code_char_count'];
        $code_char_range = $this->CodeType['code_char_range'];

        $character_keys = array_flip($code_char_range);
        $code_characters = $this->code_char_base;

        $number = 0;
        for ($i = 0; $i < count($code_characters); $i++) {
                $number = $number * $code_char_count + $character_keys[$code_characters[$i]];
        }
        $this->code_pos_num = ($number+1);
    }

    public function CodeArray(){
        $code_base = implode($this->code_char_base);
    if($this->default_code_length==strlen($code_base)){
            return array(
                    'code_base'=>$code_base,
                    'code_base_md5'=>md5($code_base),
                    'code_base_sha1'=>sha1($code_base),
                    'code_base64_encode'=>base64_encode($code_base),
                    'code_max_number'=>$this->CodeType['code_max_number'],
                    'code_pos_num'=>$this->code_pos_num,
                    'code_time'=>$this->CodeType['code_generated_time'],
                    'code_message'=>'is_acurrate',
                    'code_name'=>$this->CodeType['code_name'],
                    'code_description'=>$this->CodeType['code_description'],
                    'code_type'=>$this->default_code_type,
                    'code_max_type'=>$this->code_max_type,
                    'code_length'=>$this->default_code_length
                    );
        }elseif($this->default_code_length<strlen($code_base)){
            return array(
                        'code_base'=>$code_base,
                        'code_base_md5'=>md5($code_base),
                        'code_base_sha1'=>sha1($code_base),
                        'code_base64_encode'=>base64_encode($code_base),
                        'code_max_number'=>$this->CodeType['code_max_number'],
                        'code_pos_num'=>$this->code_pos_num,
                        'code_time'=>$this->CodeType['code_generated_time'],
                        'code_message'=>'is_upper_or_full',
                        'code_name'=>$this->CodeType['code_name'],
                        'code_description'=>$this->CodeType['code_description'],
                        'code_type'=>$this->default_code_type,
                        'code_max_type'=>$this->code_max_type,
                        'code_length'=>$this->default_code_length
                        );
        }else{
            return array(
                        'code_base'=>$code_base,
                        'code_base_md5'=>md5($code_base),
                        'code_base_sha1'=>sha1($code_base),
                        'code_base64_encode'=>base64_encode($code_base),
                        'code_max_number'=>$this->CodeType['code_max_number'],
                        'code_pos_num'=>$this->code_pos_num,
                        'code_time'=>$this->CodeType['code_generated_time'],
                        'code_message'=>'is_lower',
                        'code_name'=>$this->CodeType['code_name'],
                        'code_description'=>$this->CodeType['code_description'],
                        'code_type'=>$this->default_code_type,
                        'code_max_type'=>$this->code_max_type,
                        'code_length'=>$this->default_code_length
                        );
        }
    }

    public function Generate_String(){
        $this->CodeTypes();
        $this->CodeCreate();
        $this->CodeCountNumber();
        return $this->CodeArray();
    }

    public function Generate_ID($GenerateID){
        is_numeric($GenerateID) OR die('The ID must be numberic!');
        $this->CodeTypes();
        $code_char_count = $this->CodeType['code_char_count'];
        $code_char_range = $this->CodeType['code_char_range'];

        $one = 1;
        if($GenerateID>$this->CodeType['code_max_number']){
            //Perform reset
            $code_id = ($one - $one);
        }else{
            $code_id = ($GenerateID - $one);
        }
        for($length=($this->default_code_length - $one);$length>=0;$length--){
            if(function_exists('bcpow')){
                $bcpow = bcpow($code_char_count, $length);
                $possition = floor($code_id / $bcpow);
                $code_id = $code_id - ($possition * $bcpow);
            }else{
                $pow = pow($code_char_count, $length);
                $possition = floor($code_id / $pow);
                $code_id = $code_id - ($possition * $pow);
            }

            $this->code_char_base[$length] = $code_char_range[$possition];
        }
        $this->CodeCountNumber();
        return $this->CodeArray();
    }
}
?>


问:
What's the difference between two usages of
 tag?
Consider below code :

```<code><?php
function a($txt) {
    b("Cleveland");
}
function b($txt) {
    var_dump(debug_backtrace());
}
echo '```';
a("Peter");
'```';
?>
</code>```

Output :

```<code>array(2) {
  [0]=>
  array(4) {
    ["file"]=>
    string(40) "C:\xampp\htdocs\php_playground\hello.php"
    ["line"]=>
    int(6)
    ["function"]=>
    string(1) "b"
    ["args"]=>
    array(1) {
      [0]=>
      string(9) "Cleveland"
    }
  }
  [1]=>
  array(4) {
    ["file"]=>
    string(40) "C:\xampp\htdocs\php_playground\hello.php"
    ["line"]=>
    int(12)
    ["function"]=>
    string(1) "a"
    ["args"]=>
    array(1) {
      [0]=>
      string(5) "Peter"
    }
  }
}
</code>```

Now, consider below code :

```<code><?php
function a($txt) {
    b("Cleveland");
}
function b($txt) {
    var_dump(debug_backtrace());
}
echo '```'.a("Peter").'```';
?>
</code>```

Output :

```<code>array(2) { [0]=> array(4) { ["file"]=> string(40) "C:\xampp\htdocs\php_playground\hello.php" ["line"]=> int(3) ["function"]=> string(1) "b" ["args"]=> array(1) { [0]=> string(9) "Cleveland" } } [1]=> array(4) { ["file"]=> string(40) "C:\xampp\htdocs\php_playground\hello.php" ["line"]=> int(8) ["function"]=> string(1) "a" ["args"]=> array(1) { [0]=> string(5) "Peter" } } }
</code>```

Why I'm getting two different outputs for the two different usages of ```</code> tag?</p>

```echo '```';
a("Peter");
'```';
```

<p>AND</p>

```echo '```'.a("Peter").'```';
```

I think I'm doing nothing different in both of the statements. I'm doing almost the same thing then why I'm getting different outputs?

答:
echo only runs once it's finished building the string. So if you run

```<code>function a() {
  echo 'A';
}
echo 'Hello ' . a();
</code>```

you'll end up with the output

AHello

This is because the function is evaluated as part of building up the output to the echo call. If the function itself has an echo statement (or var_dump, print_r, etc), then it will be shown first.

There are two options to resolve this:

1) Refactor your function to return the string instead

```<code>function a() {
  return 'A';
}
echo 'Hello ' . a();
</code>```

2) Call your function as part of a separate echo call, using commas instead of string concatenation:

```<code>function a() {
  echo 'A';
}
echo 'Hello ' , a();
</code>```

In both of these cases you'll end up with the correct output:

Hello A

Specifically for your question, the output you're seeing is the output from var_dump, followed by ``````, which won't show up at all. (Or actually, as many people have mentioned now, just ```. Although this won't have been making much difference to the behaviour.)

Title: What's the difference between two usages of <pre> tag?

Body:
Consider below code :

<?php
function a($txt) {
    b("Cleveland");
}
function b($txt) {
    var_dump(debug_backtrace());
}
echo '
';
a("Peter");
'
';
?>

Output :

array(2) {
  [0]=>
  array(4) {
    ["file"]=>
    string(40) "C:\xampp\htdocs\php_playground\hello.php"
    ["line"]=>
    int(6)
    ["function"]=>
    string(1) "b"
    ["args"]=>
    array(1) {
      [0]=>
      string(9) "Cleveland"
    }
  }
  [1]=>
  array(4) {
    ["file"]=>
    string(40) "C:\xampp\htdocs\php_playground\hello.php"
    ["line"]=>
    int(12)
    ["function"]=>
    string(1) "a"
    ["args"]=>
    array(1) {
      [0]=>
      string(5) "Peter"
    }
  }
}

Now, consider below code :

<?php
function a($txt) {
    b("Cleveland");
}
function b($txt) {
    var_dump(debug_backtrace());
}
echo '
'.a("Peter").'
';
?>

Output :

array(2) { [0]=> array(4) { ["file"]=> string(40) "C:\xampp\htdocs\php_playground\hello.php" ["line"]=> int(3) ["function"]=> string(1) "b" ["args"]=> array(1) { [0]=> string(9) "Cleveland" } } [1]=> array(4) { ["file"]=> string(40) "C:\xampp\htdocs\php_playground\hello.php" ["line"]=> int(8) ["function"]=> string(1) "a" ["args"]=> array(1) { [0]=> string(5) "Peter" } } }

Why I'm getting two different outputs for the two different usages of
 tag?

echo '
';
a("Peter");
'
';

AND

echo '
'.a("Peter").'
';

I think I'm doing nothing different in both of the statements. I'm doing almost the same thing then why I'm getting different outputs?

Body:
echo only runs once it's finished building the string. So if you run

function a() {
  echo 'A';
}
echo 'Hello ' . a();

you'll end up with the output

AHello

This is because the function is evaluated as part of building up the output to the echo call. If the function itself has an echo statement (or var_dump, print_r, etc), then it will be shown first.

There are two options to resolve this:

1) Refactor your function to return the string instead

function a() {
  return 'A';
}
echo 'Hello ' . a();

2) Call your function as part of a separate echo call, using commas instead of string concatenation:

function a() {
  echo 'A';
}
echo 'Hello ' , a();

In both of these cases you'll end up with the correct output:

Hello A

Specifically for your question, the output you're seeing is the output from var_dump, followed by <pre></pre>, which won't show up at all. (Or actually, as many people have mentioned now, just <pre>. Although this won't have been making much difference to the behaviour.)


问:
"Join expression not supported" for multiple Left Join in MS Access
I have the following query which I am passing as a string in my ASP.NET project:

```<code>SELECT creditorName, amount, interestRate, interestType, interestCalculationMethod, insertedDate, o.fullName AS owner, u.fullName AS dataInsertedBy FROM ((tbl_savings s) LEFT JOIN tbl_users o ON (ownerID = o.userID)) LEFT JOIN tbl_users u ON (dataEnteredByID = u.userID);
</code>```

for which I am getting the following error:

```<code>+       $exception  {"Join expression not supported."}  System.Data.OleDb.OleDbException
</code>```

I am using MS Access 2016 as the database.

What's wrong?

答:
I found the solution on MSDN. Here's the link:

https://social.msdn.microsoft.com/Forums/office/en-US/15c36745-f7a4-4926-9687-7161e5894468/join-expression-not-supported-error-caused-by-unbracketed-join-expression-comprising-string?forum=accessdev

I apologize for not putting in the correct answer along with the link that I posted. Here is the correct answer:

```<code>select savingsID, creditorName, amount, interestRate,
    interestType, interestCalculationMethod, insertedDate,
    ownerID, o.fullName as owner,
    u.fullName as dataEnteredBy
from (
   (tbl_savings as s)
   left join tbl_users as o on s.ownerID = o.userID
) left join tbl_users as u on s.dataEnteredByID = u.userID
</code>```

Body:
I have the following query which I am passing as a string in my ASP.NET project:

SELECT creditorName, amount, interestRate, interestType, interestCalculationMethod, insertedDate, o.fullName AS owner, u.fullName AS dataInsertedBy FROM ((tbl_savings s) LEFT JOIN tbl_users o ON (ownerID = o.userID)) LEFT JOIN tbl_users u ON (dataEnteredByID = u.userID);

for which I am getting the following error:

+       $exception  {"Join expression not supported."}  System.Data.OleDb.OleDbException

I am using MS Access 2016 as the database.

What's wrong?

Body:
I found the solution on MSDN. Here's the link:

https://social.msdn.microsoft.com/Forums/office/en-US/15c36745-f7a4-4926-9687-7161e5894468/join-expression-not-supported-error-caused-by-unbracketed-join-expression-comprising-string?forum=accessdev

I apologize for not putting in the correct answer along with the link that I posted. Here is the correct answer:

select savingsID, creditorName, amount, interestRate,
    interestType, interestCalculationMethod, insertedDate,
    ownerID, o.fullName as owner,
    u.fullName as dataEnteredBy
from (
   (tbl_savings as s)
   left join tbl_users as o on s.ownerID = o.userID
) left join tbl_users as u on s.dataEnteredByID = u.userID


问:
Setting up a array of callbacks and trying to use array index as value in callback
When I setup an array of callbacks this way I get 20 in the dialog window for all callbacks.  I'd like to get the index in the array instead.  Is this possible?  The function that calls the callback is expecting the callback to have one parameter.  I don't control the caller of the callback because it is part of an external library.  Any help is appreciated.</p>

```<code>for (var i = 0; i < 20; i++) {
  callbackDB[i] = function(data) {
    alert(i);
  }
}
</code>```

答:
Because i is evaluated when the function is called, you'll need to scope that value of i in a new function execution in order to retain the value you expect.

```<code>     // returns a function that closes around the `current_i` formal parameter.
var createFunction = function( current_i ) {
    return function( data ) {
        alert( current_i );
    };
};

     // In each iteration, call "createFunction", passing the current value of "i"
     // A function is returned that references the "i" value you passed in.
for (var i = 0; i < 20; i++) {
  callbackDB[i] = createFunction( i );
}
</code>```

Body:
When I setup an array of callbacks this way I get 20 in the dialog window for all callbacks.  I'd like to get the index in the array instead.  Is this possible?  The function that calls the callback is expecting the callback to have one parameter.  I don't control the caller of the callback because it is part of an external library.  Any help is appreciated.

for (var i = 0; i < 20; i++) {
  callbackDB[i] = function(data) {
    alert(i);
  }
}

Body:
Because i is evaluated when the function is called, you'll need to scope that value of i in a new function execution in order to retain the value you expect.

     // returns a function that closes around the `current_i` formal parameter.
var createFunction = function( current_i ) {
    return function( data ) {
        alert( current_i );
    };
};

     // In each iteration, call "createFunction", passing the current value of "i"
     // A function is returned that references the "i" value you passed in.
for (var i = 0; i < 20; i++) {
  callbackDB[i] = createFunction( i );
}


问:
Math principle behind converging loop indices?
What is the general mathematics principle behind the following problem?

Take a vector containing integers e.g. [3, 3, 3, 3, 4, 6, 3, 4, 4, 5], and another vector representing loop indices that all begin at a value less than the first vector e.g. [1, 1, 1, 1, 1, 1, 1, 1, 1, 1].  When each loop index is equal to its corresponding index in the first vector, reset it to one.  Program ends when all indices are equal to one.

This seems like integer factorization, but I don't know how to state this generally.  What principle is at work here?  What is a more computationally efficient way to achieve the same result?

Thanks in advance.

```<code>import numpy as np

unityVec = np.ones((10), dtype=np.int)  # create a vector of ones
counter = 1                             # initialize counter

counterVec = np.ones((10), dtype=np.int) # initialize counter array
counterVec = counterVec + 1              # make counter array > ones array

littleVec = ([3, 3, 3, 3, 4, 6, 3, 4, 4, 5])   # loop reset values

while not (np.array_equal(unityVec, counterVec)):  # compare counter to ones vector

    counterVec = counterVec + 1

    for i in range(10):
        if counterVec[i] == littleVec[i]:
            counterVec[i] = 1  # reset counterVec element to 1 once it hits limit
            #print("Counter: ", counter, "\tIndex: ", i, "\tcounterVec: ", counterVec, "\tlittleVec: ", littleVec)

    counter = counter + 1

print("Indices converged after", counter-1, "iterations!")
</code>```

Expected result: a positive integer value that is less than or equal to the product of the first vector's values.

Experimental result: with the sample values given, the indices converge after 59 loops.

答:
I'm not sure, but it looks like simple modulo arithmetics to me. You can subtract 1 from all vectors (and do resetting to zero) to make it simpler to analyze. You start with counterVec == [a,b,c] == [1,1,1] and calculate in each iteration (where v == littleVec)

```<code>[ (a+1)%v[0], (b+1)%v[1], (c+1)%v[1] ]
</code>```

And you stop when this vector is eqal to [0,0,0].

Clearly, the first component hits zero every time a was incremented an integer multiple of v[0] times (minus one, because you start with all ones). For all elements to hit zero at once, the same statement must be true: integer multiple of the corresponding v[i].

So eventually you end up at

```<code>[ (1 + n_a * v[0] - 1)%v[0],
  (1 + n_b * v[1] - 1)%v[1],
  (1 + n_c * v[2] - 1)%v[2] ] == [ 0, 0, 0 ]
#  ^ initial value  ^ correction for the initial value
</code>```

Which is true for every choice of the integers (n_a, n_b, n_c). Since you increment all vector components jointly, there must be a smallest number of increments X such that

```<code>X = n_a * v[0]
  = n_b * v[1]
  = n_c * v[2]
</code>```

for some integers n_i. In other words, there will be a smallest X that is divisible by all of v[i]. As others have pointed out, this must be the least common multiple of all v[i]. For the numbers in your example, it's 60 (you see 59 iterations because you start with 1 and not with 0).

So if you start with

```<code>littleVec = ([5, 3, 7, 8, 10, 8, 5, 7, 5, 7])
</code>```

You will get

```<code>lcm([5, 3, 7, 8, 10, 8, 5, 7, 5, 7]-1) = 252
</code>```

minus one iterations until the loop stops.

Body:
What is the general mathematics principle behind the following problem?

Take a vector containing integers e.g. [3, 3, 3, 3, 4, 6, 3, 4, 4, 5], and another vector representing loop indices that all begin at a value less than the first vector e.g. [1, 1, 1, 1, 1, 1, 1, 1, 1, 1].  When each loop index is equal to its corresponding index in the first vector, reset it to one.  Program ends when all indices are equal to one.

This seems like integer factorization, but I don't know how to state this generally.  What principle is at work here?  What is a more computationally efficient way to achieve the same result?

Thanks in advance.

import numpy as np

unityVec = np.ones((10), dtype=np.int)  # create a vector of ones
counter = 1                             # initialize counter

counterVec = np.ones((10), dtype=np.int) # initialize counter array
counterVec = counterVec + 1              # make counter array > ones array

littleVec = ([3, 3, 3, 3, 4, 6, 3, 4, 4, 5])   # loop reset values

while not (np.array_equal(unityVec, counterVec)):  # compare counter to ones vector

    counterVec = counterVec + 1

    for i in range(10):
        if counterVec[i] == littleVec[i]:
            counterVec[i] = 1  # reset counterVec element to 1 once it hits limit
            #print("Counter: ", counter, "\tIndex: ", i, "\tcounterVec: ", counterVec, "\tlittleVec: ", littleVec)

    counter = counter + 1

print("Indices converged after", counter-1, "iterations!")

Expected result: a positive integer value that is less than or equal to the product of the first vector's values.

Experimental result: with the sample values given, the indices converge after 59 loops.

Body:
I'm not sure, but it looks like simple modulo arithmetics to me. You can subtract 1 from all vectors (and do resetting to zero) to make it simpler to analyze. You start with counterVec == [a,b,c] == [1,1,1] and calculate in each iteration (where v == littleVec)

[ (a+1)%v[0], (b+1)%v[1], (c+1)%v[1] ]

And you stop when this vector is eqal to [0,0,0].

Clearly, the first component hits zero every time a was incremented an integer multiple of v[0] times (minus one, because you start with all ones). For all elements to hit zero at once, the same statement must be true: integer multiple of the corresponding v[i].

So eventually you end up at

[ (1 + n_a * v[0] - 1)%v[0],
  (1 + n_b * v[1] - 1)%v[1],
  (1 + n_c * v[2] - 1)%v[2] ] == [ 0, 0, 0 ]
#  ^ initial value  ^ correction for the initial value

Which is true for every choice of the integers (n_a, n_b, n_c). Since you increment all vector components jointly, there must be a smallest number of increments X such that

X = n_a * v[0]
  = n_b * v[1]
  = n_c * v[2]

for some integers n_i. In other words, there will be a smallest X that is divisible by all of v[i]. As others have pointed out, this must be the least common multiple of all v[i]. For the numbers in your example, it's 60 (you see 59 iterations because you start with 1 and not with 0).

So if you start with

littleVec = ([5, 3, 7, 8, 10, 8, 5, 7, 5, 7])

You will get

lcm([5, 3, 7, 8, 10, 8, 5, 7, 5, 7]-1) = 252

minus one iterations until the loop stops.


问:
Two associations between same tables with Ruby On Rails
I have an app with Two Models Stadium & Team, they have a many-to-many relationship and are joined in the middle by a join table.

My current structure looks like this:

```<code>class Team < ActiveRecord::Base
    has_many :stadiumteams, :class_name => 'StadiumTeam'
    has_many :stadiums, :through => :stadiumteams
end

class Stadium < ActiveRecord::Base
    has_many :stadiumteams, :class_name => 'StadiumTeam'
    has_many :teams, :through => :stadiumteams
end

class StadiumTeam < ActiveRecord::Base
    belongs_to :stadium
    belongs_to :team
end
</code>```

This relationship show “current residents for a stadium”. But now I also want to have a relationship that can display old residents.

For example Tottenham (Team) used to play at White Hart Lane (Stadium) But now play at (Wembley) Stadium.

I am planning to do the following. But I am unsure if this will work or if there is a better way to do it?

Team

```<code>class Team < ActiveRecord::Base
    has_many :stadiumteams, :class_name => 'StadiumTeam'
    has_many :stadiums, :through => :stadiumteams

    #has_many :oldstadiums, :class_name => 'OldStadium'
    #has_many :stadiums, :through => :oldstadiums
end
</code>```

Stadium

```<code>class Stadium < ActiveRecord::Base

    has_many :stadiumteams, :class_name => 'StadiumTeam'
    has_many :teams, :through => :stadiumteams

    #has_many :oldstadiums, :class_name => 'OldStadium'
    #has_many :teams, :through => :oldstadiums
end
</code>```

New Join Table

```<code>class OldStadium < ActiveRecord::Base
    belongs_to :stadium
    belongs_to :team
end
</code>```

Any help is very appreciated!

EDIT: (Input fields)
Here's how the code for my inputs currently looks:

```<code><%= f.association :teams, label: 'Current Residents', class:'select2-field', placeholder: "Select teams", collection: @teams, input_html: { multiple: true }, hint: 'Select one or multiple teams.'%>

<%= f.association :teams, label: 'Old Residents', class:'select2-field', placeholder: "Select teams", collection: @teams, input_html: { multiple: true }, hint: 'Select one or multiple teams.' %>
</code>```

And my params

```<code>   def stadium_params
      params.require(:stadium).permit(:name, :capacity, :city, :country, :location_name, :address, :longitude, :latitude, :image, :surface, :official_opening_date, :cost, :web_url, :also_known_as, :record_attendance, :team_ids => [])
    end
</code>```

答:
There are several ways to fulfill your requirement. Your approach also enough, but for efficiency, since the number of Stadium is small ( thousands ), you can use STI for Stadium entity.

```<code>class Stadium < ActiveRecord::
  has_many :stadiums_teams
  has_many :teams, through: :stadiums_teams
end

class OldStadium < Stadium; end

class RecentStadium < Stadium; end

class StadiumTeam < ActiveRecord::Base
  belongs_to :stadium
  belongs_to :team
end

class Team < ActiveRecord::Base
  has_many :stadiums_teams
  has_many :stadiums, through: :stadiums_teams, source: :stadium
  has_many :old_stadiums, through: :stadiums_teams,
    source: :stadium, class_name: OldStadium.name
  has_many :recent_stadiums, through: :stadiums_teams,
    source: :stadium, class_name: RecentStadium.name
end
</code>```

So, in most case, you will work with OldStadium / RecentStadium model, but when you want to check if a team ever played at a specific stadium or not, just use Stadium model.

Body:
I have an app with Two Models Stadium & Team, they have a many-to-many relationship and are joined in the middle by a join table.

My current structure looks like this:

class Team < ActiveRecord::Base
    has_many :stadiumteams, :class_name => 'StadiumTeam'
    has_many :stadiums, :through => :stadiumteams
end

class Stadium < ActiveRecord::Base
    has_many :stadiumteams, :class_name => 'StadiumTeam'
    has_many :teams, :through => :stadiumteams
end

class StadiumTeam < ActiveRecord::Base
    belongs_to :stadium
    belongs_to :team
end

This relationship show “current residents for a stadium”. But now I also want to have a relationship that can display old residents.

For example Tottenham (Team) used to play at White Hart Lane (Stadium) But now play at (Wembley) Stadium.

I am planning to do the following. But I am unsure if this will work or if there is a better way to do it?

Team

class Team < ActiveRecord::Base
    has_many :stadiumteams, :class_name => 'StadiumTeam'
    has_many :stadiums, :through => :stadiumteams

    #has_many :oldstadiums, :class_name => 'OldStadium'
    #has_many :stadiums, :through => :oldstadiums
end

Stadium

class Stadium < ActiveRecord::Base

    has_many :stadiumteams, :class_name => 'StadiumTeam'
    has_many :teams, :through => :stadiumteams

    #has_many :oldstadiums, :class_name => 'OldStadium'
    #has_many :teams, :through => :oldstadiums
end

New Join Table

class OldStadium < ActiveRecord::Base
    belongs_to :stadium
    belongs_to :team
end

Any help is very appreciated!

EDIT: (Input fields)
Here's how the code for my inputs currently looks:

<%= f.association :teams, label: 'Current Residents', class:'select2-field', placeholder: "Select teams", collection: @teams, input_html: { multiple: true }, hint: 'Select one or multiple teams.'%>

<%= f.association :teams, label: 'Old Residents', class:'select2-field', placeholder: "Select teams", collection: @teams, input_html: { multiple: true }, hint: 'Select one or multiple teams.' %>

And my params

   def stadium_params
      params.require(:stadium).permit(:name, :capacity, :city, :country, :location_name, :address, :longitude, :latitude, :image, :surface, :official_opening_date, :cost, :web_url, :also_known_as, :record_attendance, :team_ids => [])
    end

Body:
There are several ways to fulfill your requirement. Your approach also enough, but for efficiency, since the number of Stadium is small ( thousands ), you can use STI for Stadium entity.

class Stadium < ActiveRecord::
  has_many :stadiums_teams
  has_many :teams, through: :stadiums_teams
end

class OldStadium < Stadium; end

class RecentStadium < Stadium; end

class StadiumTeam < ActiveRecord::Base
  belongs_to :stadium
  belongs_to :team
end

class Team < ActiveRecord::Base
  has_many :stadiums_teams
  has_many :stadiums, through: :stadiums_teams, source: :stadium
  has_many :old_stadiums, through: :stadiums_teams,
    source: :stadium, class_name: OldStadium.name
  has_many :recent_stadiums, through: :stadiums_teams,
    source: :stadium, class_name: RecentStadium.name
end

So, in most case, you will work with OldStadium / RecentStadium model, but when you want to check if a team ever played at a specific stadium or not, just use Stadium model.