Jump to content

  • Log In with Google      Sign In   
  • Create Account


fastcall22

Member Since 04 Feb 2008
Offline Last Active Yesterday, 11:56 PM
****-

#5159287 remapping the keyboard (esp {} () )

Posted by fastcall22 on 09 June 2014 - 10:13 AM

Write an ahk script:
f1::{
f2::}
f3::(
f4::)
Though, you wouldn't need such a script, if you had proper typing discipline... I find the function keys harder to reach than any of the bracket keys (on an EN-us keyboard, that is).


#5157983 what is most difficult in programming to you?

Posted by fastcall22 on 03 June 2014 - 07:38 PM

Naming things.


... Come on, admit it. You know it's true.


#5157893 Javascript #include implemented in Python

Posted by fastcall22 on 03 June 2014 - 12:04 PM

Additionally, javascript already manages "includes"; just not in the way you expect:
<head>
<script type="text/javascript" src="a.js"></script>
</head>
<body>
<script type="text/javascript" src="b.js"></script>
<script type="text/javascript" src="c.js"></script>
</body>
Here, 'b' knows of 'a', and 'c' knows of the others. If 'b' were to define 'foobar', it'd be visible to 'b' and 'c', but not 'a'.


#5157888 Javascript #include implemented in Python

Posted by fastcall22 on 03 June 2014 - 11:48 AM

Thoughts? Am I crazy? Wasting my time? Has this been done/solved before?

None. Yes. Yes. Yes, requirejs.


#5157684 Does C++ have a squared operator?

Posted by fastcall22 on 02 June 2014 - 05:52 PM

Cool story, now try this one:
 
#include <iostream>
 
#define POW2(x) ((x)*(x))
 
class Foobar {
public:
    Foobar() : _a(5) { }
     
    int a() {
        return _a++;
    }
      
private:
    int _a;
};
 
int main() {
    using namespace std;
     
    Foobar f;
    int x = POW2(f.a());
     
    cout << x << endl;
}



#5155767 check if char is displayable character

Posted by fastcall22 on 24 May 2014 - 07:30 PM

On an en-US keyboard? Check the ASCII chart, any characters between 32 and 126 are "printable".


#5153417 Excel Index(Match()) questions

Posted by fastcall22 on 13 May 2014 - 04:17 PM

The correct answer is to use a pivot table.

A pivot table will allow you to group data by values in a certain column (such as your "Location" column) and aggregate other data (such as summing the "Usage" for every "Product" or "Location" or both. Here's a random tutorial I found with more explanation.


#5152563 Percentage of chance

Posted by fastcall22 on 09 May 2014 - 11:31 AM

Not sure about HeroCloud, but generally you get a floating point number between 0 and 1, and test if it's equal to or lower than 0.05:
crit_chance = 0.05
if rand_float(0,1) < crit_chance
   damage *= 1.5
For a more "natural" random, you increase the 5% chance by some rate for every failure and reset it when it succeeds:
if rand_float(0,1) < (crit_chance + error)
   damage *= 1.5
   error = 0
else
   # Increase chance by 6.75%
   error += crit_chance * 0.0675
EDIT: Juliean is correct, I done goofed.


#5152459 Names names names

Posted by fastcall22 on 08 May 2014 - 10:13 PM

Any name can sound good, if you can justify it against its culture. With a developed culture, you can develop the traditions, the language, the dialect, the names... If you have these developed first, then the names start to come easily.


Also, Streetlamp Le Moose for president.


#5152458 Force feedback the same as vibration.

Posted by fastcall22 on 08 May 2014 - 10:03 PM

Because marketing.

Haptic technology ("force feedback") encompasses both physical resistance and vibrations.


#5151192 scanset's and zero sized results breaking parsing.

Posted by fastcall22 on 03 May 2014 - 08:47 AM

If you are only splitting by pipe and newline, have you considered using strtok instead?


#5150779 Sort Multidimensional Array

Posted by fastcall22 on 01 May 2014 - 12:38 PM

I'm not so sure I understand what you want me to do...

Do you want me to swap out what is there with the code you provided?

Sorry I wasn't very clear in my previous post. The purpose of my previous post was to demonstrate why you shouldn't use the qsort code you "found elsewhere". Each snippet is a fully working example; that is, you can copy the code, dump it into your browser's javascript console, and get the output as shown by the comments. You are correct that I modified the qsort array to take a comparator function, but other than that, the function is completely identical.

I also don't understand what this "console.log(arr.join(', ')); // 5, 4, 2, 1, 3, -1, -2, 0, -4, -3, -5 (wat)" is for. Is that for debugging or something?

Yes. console.log outputs a message to your browser's console window. arr.join(', ') concatenates the array's elements into a string with a comma and a space between the elements. The comment to the side shows what is output to the console. The "(wat)" is to draw focus to qsort's complete inability to sort elements correctly.

The problem I'm having is comes from the fact that it is an array of array rather than 1 field of an array being compared with another. I guess I should have made these objects rather than arrays. Maybe that'd make this whole thing easier.

Regardless of whether you use objects or arrays, the code would more or less be the same:
function compare(a,b) {
  // a and b are rows in Star; as rows in Star
  for ( var depth = 0; depth < a.length && depth < b.length; ++depth ) {
    if ( a[depth] < b[depth] )
      return -1;
    else if ( a[depth] > b[depth] )
      return 1;
  }
  return 0;
}

Star.sort(compare);

Also,

Fastcoder

I don't know who this fastcoder guy is, but apparently you're from the future and Swiftcoder and I must get married and have many beautiful children together. :9


#5150691 Sort Multidimensional Array

Posted by fastcall22 on 30 April 2014 - 11:27 PM

Get rid of that garbage qsort:
var swap = function (array, a, b ) {
    var tmp = array[a];
    array[a] = array[b];
    array[b] = tmp;
};
var qsort = function ( array, lo, hi, f ) {
  var low  = lo;
  var high = hi;
  mid = Math.floor( (low+high)/2 );

  do {
    while ( f(array, low,  mid) > 0 )
      low++;

    while ( f(array, high, mid) < 0 )
      high--;

    if ( low <= high ) {
      swap( array, low, high );
      low++;
      high--;
    }

  } while ( low <= high );

  if ( high > lo )
    qsort( array, lo, high, f );

  if ( low < hi )
    qsort( array, low, hi, f );
};

var int_comparator = function(arr,a,b) {
  return arr[a]-arr[b];
};

var arr = [-1,1,2,5,-2,4,-4,-5,-3,3,0];

var f = int_comparator;

qsort(arr,0,arr.length-1,f);
console.log(arr.join(', '));   // 5, 4, 2, 1, 3, -1, -2, 0, -4, -3, -5 (wat)

qsort(arr,0,arr.length-1,f);
console.log(arr.join(', '));   // 5, 4, 3, 2, 1, 0, -1, -2, -3, -4, -5
And use Array.prototype.sort instead:
var f = function(a,b) {
  return a-b;
}
var arr = [-1,1,2,5,-2,4,-4,-5,-3,3,0];
arr.sort(f);
console.log(arr.join(', '));   // -5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5
Additionally, you are creating one more element than intended, since a loop from 0 to N inclusive iterates N+1 times; an array sized N has elements indexable from [0 N).


EDIT: Shame on me... Lazy copy-pasta.
EDIT2: Missed the swap function.



#5150638 Sort Multidimensional Array

Posted by fastcall22 on 30 April 2014 - 03:28 PM

Array.prototype.sort?


#5150633 Sort Multidimensional Array

Posted by fastcall22 on 30 April 2014 - 02:57 PM

In case someone with the same problem stumbles upon this thread, here's the pseudo code for sorting by multiple properties:

compare a, b:
  for property in properties:
    aa = a[property]
    bb = b[property]

    if aa < bb
      return true
    if aa > bb
      return false
  
  # a equals b
  return false





PARTNERS