text:
Q: how do I implement if condition in my cloudformation stack I have two attributes in my stack enviornment and iamprofileName. If I select one of the non-prod enviornment i.e "use1dev","use1qa". I should get MyPlatformEC2NonProd as default value in "IAMProfileName"
If I select one of the prod enviornments i.e   "useProd1","useProd2".I must get MyPlatformEC2Prod as default value in "IAMProfileName"
How can I achieve this
"Environment" : {
        "Description" : "Environment being deployed to - use1dev, use1qa,
use1sbox etc",
        "Type" : "String",
        "Default" : "use1sbox",
        "AllowedValues" : ["use1dev","use1qa","useProd1","useProd2"]
    },
    "IAMProfileName" : {
        "Default" : "MyPlatformEC2",
        "Type" : "String",
        "Description" : "Name of IAM profile to attach to created
machines",
        "AllowedValues" : ["MyPlatformEC2","MyPlatformEC2NonProd"]

A: Use CloudFormation conditions. For example in your case, I would do something like the following:
Conditions:
    "ProdProfileCondition": {
       "Fn::Or": [
          {"Fn::Equals": ["useProd1", {"Ref": "Environment"}]},
          {"Fn::Equals": ["useProd2", {"Ref": "Environment"}]},
       ]
    }

Now wherever you want to use the IAMProfileName value, use something like the following,
SomeAWSResource:
Properties:
    "ProfileName" : [{
      "Fn::If" : [
        "ProdProfileCondition",
        {"Ref" : "MyPlatformEC2"},
        {"Ref" : "MyPlatformEC2NonProd"}
      ]
    }]

For more information on how to use conditionals, check out the following link.
Also, you can achieve more complicated conditionals using Jinja, just create a template and fill values according to conditions. But I wouldn't go into details of that because what you need can be fulfilled by this already.
https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/intrinsic-function-reference-conditions.html


text:
Q: Static lib 3.1.3 + App 3.2/4.0b2: initWithNibName:bundle: corrupting ivar I have a static library built with 3.1.3. I'm including it into an application, which I'm building with 3.2/4.0b2.
The static library contains a UIViewController subclass, which in it's -init calls [super initWithNibName:nil bundle:nil].
This method in turn calls _doCommonSetup, which corrupts one of the subclass's ivars:
0x003a68e9  <+0014>  pop    %ebx
0x003a68ea  <+0015>  mov    0x8(%ebp),%esi
0x003a68ed  <+0018>  movl   $0x1,0x8(%esp)
0x003a68f5  <+0026>  mov    0x1d98327(%ebx),%eax
0x003a68fb  <+0032>  mov    %eax,0x4(%esp)
0x003a68ff  <+0036>  mov    %esi,(%esp)
0x003a6902  <+0039>  call   0x20e5f52 <dyld_stub_objc_msgSend>
0x003a6907  <+0044>  movl   $0x44898000,0x70(%esi)  <- corrupting subclass's ivar (setting it to 0x4489..)

I can use the static library fine with applications built with 3.0 or 3.1.3. But 3.2 and 4.0 cause problems.
Is this supposed to work, or can the static library be used only within apps that are build with same or older version of the SDK it was built with?

A: This was because 4.0 is using the modern runtime even on the simulator, while older versions were not. Compiled libraries are not compatible.

redpajama_set_name: RedPajamaStackExchange


text:
Q: How to fill Imageview letter / character in Swift? I am a beginner in iOS. I am working on the character fill up of UIImageView. Like if image show "R" user need to draw/fill "R" Character then next character show. How can I achieve that?
Example :

Below snippet of code try from my side (in Objective - C):
CGPoint currentPoint = pointB;

if ([UIScreen.mainScreen respondsToSelector:@selector(scale)]) {
    UIGraphicsBeginImageContextWithOptions(self.frame.size, NO, UIScreen.mainScreen.scale);
}
else {
    UIGraphicsBeginImageContext(self.frame.size);
}

[tempDrawImage.image drawInRect:CGRectMake(0, 0, self.frame.size.width, self.frame.size.height)];
CGContextMoveToPoint(UIGraphicsGetCurrentContext(), pointA.x, pointA.y);
CGContextAddLineToPoint(UIGraphicsGetCurrentContext(), currentPoint.x, currentPoint.y);
CGContextSetLineCap(UIGraphicsGetCurrentContext(), kCGLineCapRound);
CGContextSetLineWidth(UIGraphicsGetCurrentContext(), brush );
CGContextSetRGBStrokeColor(UIGraphicsGetCurrentContext(), red, green, blue, 1.0);
CGContextSetBlendMode(UIGraphicsGetCurrentContext(),kCGBlendModeNormal);

CGContextStrokePath(UIGraphicsGetCurrentContext());
tempDrawImage.image = UIGraphicsGetImageFromCurrentImageContext();
[tempDrawImage setAlpha:opacity];
UIGraphicsEndImageContext();

UIGraphicsBeginImageContext(tempDrawImage.frame.size);
[tempDrawImage.image drawInRect:CGRectMake(0, 0, self.frame.size.width, self.frame.size.height) blendMode:kCGBlendModeNormal alpha:opacity];
UIGraphicsEndImageContext();

Let me know how to achieve this functionality.


text:
Q: How to use Otto event bus with Android Annotations I am working on an app where I want to use Android Annotations and Otto Bus Event from Square
For the integration of these two libraries together I have followed this link here. Also I have used the Otto 2.0-wip lib that is suggested there and not that from Otto Git.
This is how I do the implementation:
I created a singleton class for the bus:
@EBean(scope = EBean.Scope.Singleton)
public class BusProviderAA extends BasicBus{
}

I declare an object for this class inside my Fragment Class where I want to subscribe at events :
@Bean
BusProviderAA ottoBus;

@AfterInject
protected void initAfterInjectMFragment()
     .... // my stuff here
    ottoBus.register(this);
}

@Override
public void onStop() {
    super.onStop();
    ottoBus.unregister(this);
}

@Subscribe
public void onChangeUserDetailsEvent(ChangeUserDetailsEvent mEvent){
    Log.e(" s onChangeUserDetailsEvent", "ss onChangeUserDetailsEvent");

    if(mEvent.msg.contains("Data_changed")){
        //TODO
    }

}

I post event to the bus from my communicator class when it gets callback from server communication.
This is how I post event to my bus inside this class:
@Bean //To use this enhanced class in another enhanced class or in an enhanced Android component, use @Bean:
BusProviderAA ottoBus;

public void callbackResponse(....){
....// my stuff here and after callback
ottoBus.post(changeUserDetailsEvent(serverResponse.getMsg()));
}

@Produce
public ChangeUserDetailsEvent changeUserDetailsEvent(String msg){
    return new ChangeUserDetailsEvent(msg);
}

And this is my ChangeUserDetailsEvent class:
public class ChangeUserDetailsEvent {

   public final String msg;

   public ChangeUserDetailsEvent(String msg) {
       this.msg = msg;
   }
}

Problem:
My problem is that my method which is subscribed at bus event onChangeUserDetailsEvent doesnt get called and I dont even know how to debug to fix this problem.
I should mention that bus event works perfectly when I implement it in a Fragment that doesn't use Annotations, and a Bus singleton without Annotation. This is the Bus singleton class when I don't use Annotations:
public class BusProvider {

   private static final Bus BUS = new BasicBus(); // me lib

   public static Bus getInstance(){
       return BUS;
   }

   private BusProvider(){}
}

Thanks!
EDIT
I also have a problem when I update to androidannotations:3.2 changing my gradle file from:
compile 'org.androidannotations:androidannotations:3.1'
apt 'org.androidannotations:androidannotations:3.1'
to:
compile 'org.androidannotations:androidannotations:3.2'
apt 'org.androidannotations:androidannotations:3.2'.
For version 3.1 it compiles but doesnt work otto event bus. With version 3.2 it gives error.This means that AA library has made some changes that I need to implement or it has bugs. How can I find the solution ?
This is one of the errors(for demonstration): Error:(27, 25) error: cannot find symbol class UserAccountActivity_ which is a class that is activity.
This is my androidannotations.log:
17:26:05.187 [Daemon Thread 13] INFO  o.a.AndroidAnnotationProcessor:84 - Initialize AndroidAnnotations 3.2 with options {androidManifestFile=C:\Users\Armando\Android Studio\Hu\app\build\intermediates\manifests\full\debug\AndroidManifest.xml, resourcePackageName=XXPack}
17:26:05.244 [Daemon Thread 13] INFO  o.a.AndroidAnnotationProcessor:108 - Start processing for 15 annotations on 100 elements
17:26:05.273 [Daemon Thread 13] DEBUG o.a.h.AndroidManifestFinder:98 - AndroidManifest.xml file found with specified path: C:\Users\Armando\Android Studio\Hu\app\build\intermediates\manifests\full\debug\AndroidManifest.xml
17:26:05.279 [Daemon Thread 13] INFO  o.a.AndroidAnnotationProcessor:171 - AndroidManifest.xml found: AndroidManifest [applicationPackage=XXPack, componentQualifiedNames=[XXPack.SplashScreen, XXPack.HomeActivity, XXPack.ActivityProve, XXPack.UserAccountActivity_, XXPack.CartActivity_, com.facebook.LoginActivity], permissionQualifiedNames=[android.permission.INTERNET, android.permission.READ_EXTERNAL_STORAGE, android.permission.write_external_storage], applicationClassName=null, libraryProject=false, debugabble=false, minSdkVersion=14, maxSdkVersion=-1, targetSdkVersion=21]
17:26:05.280 [Daemon Thread 13] INFO  o.a.r.ProjectRClassFinder:50 - Found project R class: XXPack.R
17:26:05.286 [Daemon Thread 13] INFO  o.a.r.AndroidRClassFinder:44 - Found Android class: android.R
17:26:05.304 [Daemon Thread 13] INFO  o.a.p.ModelValidator:42 - Validating elements
17:26:05.304 [Daemon Thread 13] DEBUG o.a.p.ModelValidator:62 - Validating with EActivityHandler: [XXPack.CartActivity, XXPack.UserAccountActivity]
17:26:05.306 [Daemon Thread 13] DEBUG o.a.p.ModelValidator:62 - Validating with EFragmentHandler: [XXPack.fragments.AddAddressFragment, XXPack.fragments.AddressBookFragment, XXPack.fragments.ChangePasswordFragment, XXPack.fragments.MyOrdersFragment, XXPack.fragments.MyVouchersFragment, XXPack.fragments.NewsLetterFragment, XXPack.fragments.PaymentMethodFragment, XXPack.fragments.PersonalDataFragment, XXPack.fragments.UserAccountFragment]
17:26:05.308 [Daemon Thread 13] DEBUG o.a.p.ModelValidator:62 - Validating with EBeanHandler: [XXPack.bus.BusProviderAA, XXPack.communicator.UserAccountCommunicator]
17:26:05.308 [Daemon Thread 13] DEBUG o.a.p.ModelValidator:62 - Validating with EViewGroupHandler: [XXPack.layouts.AddressBookItem, XXPack.layouts.CartItem, XXPack.layouts.OrdersItem, XXPack.layouts.UserAccountListFooter, XXPack.layouts.UserAccountListHeader]
17:26:05.319 [Daemon Thread 13] DEBUG o.a.p.ModelValidator:62 - Validating with ItemClickHandler: [lv_user_account(int)]
17:26:05.321 [Daemon Thread 13] DEBUG o.a.p.ModelValidator:62 - Validating with OptionsMenuHandler: [XXPack.fragments.UserAccountFragment]
17:26:05.323 [Daemon Thread 13] DEBUG o.a.p.ModelValidator:62 - Validating with BeanHandler: [ottoBus, ottoBus, communicator]
17:26:05.324 [Daemon Thread 13] DEBUG o.a.p.ModelValidator:62 - Validating with ProduceHandler: [produceNonceEvent(XXPack.models.Nonce), produceErrorEvent(XXPack.models.ErrorCommunication), produceFeatureCategoryEvent(java.util.ArrayList<XXPack.models.SimpleCategory>), produceErrorEvent(XXPack.models.ErrorCommunication), produceProductEvent(java.util.ArrayList<XXPack.models.Product>), produceErrorEvent(XXPack.models.ErrorCommunication), changeUserDetailsEvent(java.lang.String), produceErrorEvent(XXPack.models.ErrorCommunication), produceUserEvent(XXPack.models.User), produceErrorEvent(XXPack.models.ErrorCommunication)]
17:26:05.325 [Daemon Thread 13] WARN  o.a.p.ModelValidator:69 - Element ProduceHandler unvalidated by
17:26:05.325 [Daemon Thread 13] WARN  o.a.p.ModelValidator:69 - Element ProduceHandler unvalidated by
17:26:05.325 [Daemon Thread 13] WARN  o.a.p.ModelValidator:69 - Element ProduceHandler unvalidated by
17:26:05.325 [Daemon Thread 13] WARN  o.a.p.ModelValidator:69 - Element ProduceHandler unvalidated by
17:26:05.326 [Daemon Thread 13] WARN  o.a.p.ModelValidator:69 - Element ProduceHandler unvalidated by
17:26:05.326 [Daemon Thread 13] WARN  o.a.p.ModelValidator:69 - Element ProduceHandler unvalidated by
17:26:05.326 [Daemon Thread 13] ERROR o.a.h.AnnotationHelper:126 - @com.squareup.otto.Produce can only be used on a method with zero parameter, instead of 1
17:26:05.327 [Daemon Thread 13] WARN  o.a.p.ModelValidator:69 - Element ProduceHandler unvalidated by
17:26:05.327 [Daemon Thread 13] ERROR o.a.h.AnnotationHelper:126 - @com.squareup.otto.Produce can only be used on a method with zero parameter, instead of 1
17:26:05.327 [Daemon Thread 13] WARN  o.a.p.ModelValidator:69 - Element ProduceHandler unvalidated by
17:26:05.327 [Daemon Thread 13] WARN  o.a.p.ModelValidator:69 - Element ProduceHandler unvalidated by
17:26:05.328 [Daemon Thread 13] WARN  o.a.p.ModelValidator:69 - Element ProduceHandler unvalidated by
17:26:05.328 [Daemon Thread 13] DEBUG o.a.p.ModelValidator:62 - Validating with SubscribeHandler: [onNonceEvent(XXPack.event.NonceEvent), onErrorEvent(XXPack.event.ErrorEvent), onFeaturesAndCategory(XXPack.event.FeatureCategoryEvent), onNonceEvent(XXPack.event.NonceEvent), onErrorEvent(XXPack.event.ErrorEvent), onUserEvent(XXPack.event.UserEvent), onChangeUserDetailsEvent(XXPack.event.ChangeUserDetailsEvent)]
17:26:05.328 [Daemon Thread 13] WARN  o.a.p.ModelValidator:69 - Element SubscribeHandler unvalidated by
17:26:05.328 [Daemon Thread 13] WARN  o.a.p.ModelValidator:69 - Element SubscribeHandler unvalidated by
17:26:05.328 [Daemon Thread 13] WARN  o.a.p.ModelValidator:69 - Element SubscribeHandler unvalidated by
17:26:05.328 [Daemon Thread 13] WARN  o.a.p.ModelValidator:69 - Element SubscribeHandler unvalidated by
17:26:05.328 [Daemon Thread 13] WARN  o.a.p.ModelValidator:69 - Element SubscribeHandler unvalidated by
17:26:05.328 [Daemon Thread 13] WARN  o.a.p.ModelValidator:69 - Element SubscribeHandler unvalidated by
17:26:05.328 [Daemon Thread 13] DEBUG o.a.p.ModelValidator:62 - Validating with AfterInjectHandler: [initAfterInjectCart(), initAfterInjectAddAddress(), initAfterInjectAddressBook(), initAfterInjectChangePass(), initAfterInjectAddressBook(), initAfterInjectPersonalData()]
17:26:05.328 [Daemon Thread 13] DEBUG o.a.p.ModelValidator:62 - Validating with AfterViewsHandler: [initAfterViewsCart(), initUserAccountAct(), initAddAddressFragment(), initAddressFragment(), initChangePassFragment(), initMyOrdersFragment(), initMyVoucherFragment(), initNewsLetterFragment(), initPaymentFragment(), initViewsAfterViews(), initUserAccountFragment()]
17:26:05.333 [Daemon Thread 13] INFO  o.a.p.ModelProcessor:69 - Processing root elements
17:26:05.338 [Daemon Thread 13] DEBUG o.a.p.ModelProcessor:160 - Processing root elements EActivityHandler: [XXPack.UserAccountActivity, XXPack.CartActivity]
17:26:05.353 [Daemon Thread 13] DEBUG o.a.p.ModelProcessor:160 - Processing root elements EFragmentHandler: [XXPack.fragments.AddressBookFragment, XXPack.fragments.AddAddressFragment, XXPack.fragments.NewsLetterFragment, XXPack.fragments.MyOrdersFragment, XXPack.fragments.UserAccountFragment, XXPack.fragments.PaymentMethodFragment, XXPack.fragments.PersonalDataFragment, XXPack.fragments.ChangePasswordFragment, XXPack.fragments.MyVouchersFragment]
17:26:05.358 [Daemon Thread 13] DEBUG o.a.p.ModelProcessor:160 - Processing root elements EBeanHandler: [XXPack.bus.BusProviderAA, XXPack.communicator.UserAccountCommunicator]
17:26:05.358 [Daemon Thread 13] DEBUG o.a.p.ModelProcessor:160 - Processing root elements EViewGroupHandler: [XXPack.layouts.CartItem, XXPack.layouts.UserAccountListFooter, XXPack.layouts.OrdersItem, XXPack.layouts.AddressBookItem, XXPack.layouts.UserAccountListHeader]
17:26:05.363 [Daemon Thread 13] INFO  o.a.p.ModelProcessor:77 - Processing enclosed elements
17:26:05.368 [Daemon Thread 13] INFO  o.a.AndroidAnnotationProcessor:250 - Number of files generated by AndroidAnnotations: 18
17:26:05.368 [Daemon Thread 13] INFO  o.a.g.ApiCodeGenerator:52 - Writting following API classes in project: []
17:26:05.373 [Daemon Thread 13] DEBUG o.a.g.SourceCodewriter:55 - Generating class: XXPack.bus.BusProviderAA_
17:26:05.388 [Daemon Thread 13] DEBUG o.a.g.SourceCodewriter:55 - Generating class: XXPack.layouts.AddressBookItem_
17:26:05.456 [Daemon Thread 13] DEBUG o.a.g.SourceCodewriter:55 - Generating class: XXPack.layouts.CartItem_
17:26:05.468 [Daemon Thread 13] DEBUG o.a.g.SourceCodewriter:55 - Generating class: XXPack.layouts.OrdersItem_
17:26:05.480 [Daemon Thread 13] DEBUG o.a.g.SourceCodewriter:55 - Generating class: XXPack.layouts.UserAccountListFooter_
17:26:05.491 [Daemon Thread 13] DEBUG o.a.g.SourceCodewriter:55 - Generating class: XXPack.layouts.UserAccountListHeader_
17:26:05.500 [Daemon Thread 13] DEBUG o.a.g.SourceCodewriter:55 - Generating class: XXPack.CartActivity_
17:26:05.514 [Daemon Thread 13] DEBUG o.a.g.SourceCodewriter:55 - Generating class: XXPack.UserAccountActivity_
17:26:05.529 [Daemon Thread 13] DEBUG o.a.g.SourceCodewriter:55 - Generating class: XXPack.fragments.AddAddressFragment_
17:26:05.546 [Daemon Thread 13] DEBUG o.a.g.SourceCodewriter:55 - Generating class: XXPack.fragments.AddressBookFragment_
17:26:05.559 [Daemon Thread 13] DEBUG o.a.g.SourceCodewriter:55 - Generating class: XXPack.fragments.ChangePasswordFragment_
17:26:05.587 [Daemon Thread 13] DEBUG o.a.g.SourceCodewriter:55 - Generating class: XXPack.fragments.MyOrdersFragment_
17:26:05.600 [Daemon Thread 13] DEBUG o.a.g.SourceCodewriter:55 - Generating class: XXPack.fragments.MyVouchersFragment_
17:26:05.613 [Daemon Thread 13] DEBUG o.a.g.SourceCodewriter:55 - Generating class: XXPack.fragments.NewsLetterFragment_
17:26:05.624 [Daemon Thread 13] DEBUG o.a.g.SourceCodewriter:55 - Generating class: XXPack.fragments.PaymentMethodFragment_
17:26:05.634 [Daemon Thread 13] DEBUG o.a.g.SourceCodewriter:55 - Generating class: XXPack.fragments.PersonalDataFragment_
17:26:05.649 [Daemon Thread 13] DEBUG o.a.g.SourceCodewriter:55 - Generating class: XXPack.fragments.UserAccountFragment_
17:26:05.664 [Daemon Thread 13] DEBUG o.a.g.SourceCodewriter:55 - Generating class: XXPack.communicator.UserAccountCommunicator_
17:26:05.670 [Daemon Thread 13] INFO  o.a.p.TimeStats:81 - Time measurements: [Whole Processing = 426 ms], [Generate Sources = 302 ms], [Process Annotations = 40 ms], [Extract Annotations = 27 ms], [Validate Annotations = 25 ms], [Find R Classes = 18 ms], [Extract Manifest = 6 ms],
17:26:05.671 [Daemon Thread 13] INFO  o.a.AndroidAnnotationProcessor:122 - Finish processing

A: AndroidAnnotations 3.1 had a bug: it did not process the Produce and Subscribe annotations. In AA 3.2 i fixed this problem.
You can ask why AA has to process these annotations at all? Unfortunetaly Otto cannot read annotations from parent classes. But with AA, you always use the generated subclass. It means when Otto processes the generated subclass it does not find any Otto annotations, that is why your event handler method did not get called. To work around this problem, we added two annotation handlers, which process Subscribe and Produce. These handlers only override the method in the generated class and copy the Otto annotations to those methods. This way Otto can read the annotations in the generated class.
For example:
@EActivity(R.layout.activity_my)
class MyActivity extends Activity{

  @Produce
  public Event produce() {
    return ...; // create the event
  }

}

class MyActivity_ extends MyActivity {

  ...

  @Produce
  @Override
  public Event produce() {
    return super.produce();
  }
}

The @Produceannotated cannot have any arguments, since Otto cannot figure out what you want to pass to it when it calls the method (Otto doc).


text:
Q: $wpdb->update() not working I am modifying an existing plugin by creating an extension to it. I am trying to update a row with basic info just to test to see if the $wpdb->update works, but even using plain values it seems to get stuck. Please take a look at this image. The form keeps showing the working symbol but when I look in the database a new row has already been created, so the post went through. I think it is getting stuck on my lines of code below. I read some other similar questions on this website where people solved the problem by putting the $data and $where terms into variables, so I did that. It made it easier to read, but it doesn't seem to fix my problems.
$amount_field_col = array('post_amount' => '12.15');
$where_clause = array('ID' => '30');
$wpdb->update('wp_posts', $amount_field_col, $where_clause);

Any idea why it might not be updatig the row and why it could be getting stuck? The overall goal here is that I made a new field to an existing form and I want to be able to take inputs to the form and plug it into a new column I made in PHPMyAdmin called post_amount.

A: I think I figured it out. The function that this code is in did not have global $wpdb; declared. I simply added that in above my code and it correctly update the row with ID = 30.
Question for more experienced people - So by default, does each function forget about all other variables previously declared, even GLOBALS? I see in this plugin code that this variable was declared in its activation.php file, so I thought it would "remember" that $wpdb was declared.


text:
Q: Proof that a binary [n, k] code, C, has 2^(n-k) cosets... I know this is an amateur question, but I am confused as to why this is true.
I've thought about it like this: |C| = 2^k, and |[GF(2)]^n| = 2^n, so there are 2^n - 2^k distinct vectors in GF(2)^n and not in C, and each one generates a single coset.
Thus, there should be 2^n - 2^k + 1 cosets (since C itself is a coset), but I am obviously wrong so I'm not sure how to prove this properly.  Any help is massively appreciated.  Thanks!

A: You are correct up to this: $|C| = 2^k$, and $|GF(2^n)|=F_2^n = 2^n$, so there are $2^n - 2^k$ distinct vectors in $GF(2^n)$ and not in $C$.
But each one not generates a single coset. In every coset, there are $2^k$ elements, so there are $\frac{2^n}{2^k}= 2^{n-k}$ cosets in $F_2^n$.


text:
Q: Hadoop MapReduce job starts but can not find Map class? My MapReduce app counts usage of field values in a Hive table. I managed to build and run it from Eclipse after including all jars from /usr/lib/hadood, /usr/lib/hive and /usr/lib/hcatalog directories. It works.
After many frustrations I have also managed to compile and run it as Maven project:
 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.bigdata.hadoop</groupId>
<artifactId>FieldCounts</artifactId>
  <packaging>jar</packaging>
  <name>FieldCounts</name>
  <version>0.0.1-SNAPSHOT</version>
  <url>http://maven.apache.org</url>

  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  </properties>
<dependencies>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>3.8.1</version>
      <scope>test</scope>
    </dependency>
<dependency>
    <groupId>org.apache.hadoop</groupId>
    <artifactId>hadoop-client</artifactId>
    <version>2.3.0</version>
</dependency>
<dependency>
    <groupId>org.apache.hcatalog</groupId>
    <artifactId>hcatalog-core</artifactId>
    <version>0.11.0</version>
</dependency>
</dependencies>
</project>

To run the job from command line the following script has to be used :
#!/bin/sh
export LIBJARS=/usr/lib/hcatalog/share/hcatalog/hcatalog-core.jar,/usr/lib/hive/lib/hive-exec-0.12.0.2.0.6.1-101.jar,/usr/lib/hive/lib/hive-metastore-0.12.0.2.0.6.1-101.jar,/usr/lib/hive/lib/libfb303-0.9.0.jar,/usr/lib/hive/lib/jdo-api-3.0.1.jar,/usr/lib/hive/lib/antlr-runtime-3.4.jar,/usr/lib/hive/lib/datanucleus-api-jdo-3.2.1.jar,/usr/lib/hive/lib/datanucleus-core-3.2.2.jar
export HADOOP_CLASSPATH=${HADOOP_CLASSPATH}:.:/usr/lib/hcatalog/share/hcatalog/hcatalog-core.jar:/usr/lib/hive/lib/hive-exec-0.12.0.2.0.6.1-101.jar:/usr/lib/hive/lib/hive-metastore-0.12.0.2.0.6.1-101.jar:/usr/lib/hive/lib/libfb303-0.9.0.jar:/usr/lib/hive/lib/jdo-api-3.0.1.jar:/usr/lib/hive/lib/antlr-runtime-3.4.jar:/usr/lib/hive/lib/datanucleus-api-jdo-3.2.1.jar:/usr/lib/hive/lib/datanucleus-core-3.2.2.jar
hadoop jar FieldCounts-0.0.1-SNAPSHOT.jar com.bigdata.hadoop.FieldCounts -libjars ${LIBJARS} simple simpout

Now Hadoop creates and starts the job that next fails because Hadoop can not find Map class:
14/03/26 16:25:58 INFO mapreduce.Job: Running job: job_1395407010870_0007
14/03/26 16:26:07 INFO mapreduce.Job: Job job_1395407010870_0007 running in uber mode : false
14/03/26 16:26:07 INFO mapreduce.Job:  map 0% reduce 0%
14/03/26 16:26:13 INFO mapreduce.Job: Task Id : attempt_1395407010870_0007_m_000000_0, Status : FAILED
Error: java.lang.RuntimeException: java.lang.ClassNotFoundException: Class com.bigdata.hadoop.FieldCounts$Map not found
at org.apache.hadoop.conf.Configuration.getClass(Configuration.java:1720)
at org.apache.hadoop.mapreduce.task.JobContextImpl.getMapperClass(JobContextImpl.java:186)
at org.apache.hadoop.mapred.MapTask.runNewMapper(MapTask.java:721)
at org.apache.hadoop.mapred.MapTask.run(MapTask.java:339)
at org.apache.hadoop.mapred.YarnChild$2.run(YarnChild.java:162)
at java.security.AccessController.doPrivileged(Native Method)
at javax.security.auth.Subject.doAs(Subject.java:396)
at org.apache.hadoop.security.UserGroupInformation.doAs(UserGroupInformation.java:1491)
at org.apache.hadoop.mapred.YarnChild.main(YarnChild.java:157)
Caused by: java.lang.ClassNotFoundException: Class com.bigdata.hadoop.FieldCounts$Map not found
at org.apache.hadoop.conf.Configuration.getClassByName(Configuration.java:1626)
at org.apache.hadoop.conf.Configuration.getClass(Configuration.java:1718)
... 8 more

Why this happen? Job jar contains all classes including Map:
 jar tvf FieldCounts-0.0.1-SNAPSHOT.jar
     0 Wed Mar 26 15:51:06 MSK 2014 META-INF/
   121 Wed Mar 26 15:51:04 MSK 2014 META-INF/MANIFEST.MF
     0 Wed Mar 26 14:29:58 MSK 2014 com/
     0 Wed Mar 26 14:29:58 MSK 2014 com/bigdata/
     0 Wed Mar 26 14:29:58 MSK 2014 com/bigdata/hadoop/
  3992 Fri Mar 21 17:29:22 MSK 2014 hive-site.xml
  4093 Wed Mar 26 14:29:58 MSK 2014 com/bigdata/hadoop/FieldCounts.class
  2961 Wed Mar 26 14:29:58 MSK 2014 com/bigdata/hadoop/FieldCounts$Reduce.class
  1621 Wed Mar 26 14:29:58 MSK 2014 com/bigdata/hadoop/TableFieldValueKey.class
  4186 Wed Mar 26 14:29:58 MSK 2014 com/bigdata/hadoop/FieldCounts$Map.class
     0 Wed Mar 26 15:51:06 MSK 2014 META-INF/maven/
     0 Wed Mar 26 15:51:06 MSK 2014 META-INF/maven/com.bigdata.hadoop/
     0 Wed Mar 26 15:51:06 MSK 2014 META-INF/maven/com.bigdata.hadoop/FieldCounts/
  1030 Wed Mar 26 14:28:22 MSK 2014 META-INF/maven/com.bigdata.hadoop/FieldCounts/pom.xml
   123 Wed Mar 26 14:30:02 MSK 2014 META-INF/maven/com.bigdata.hadoop/FieldCounts/pom.properties
[hdfs@localhost target]$ jar tvf FieldCounts-0.0.1-SNAPSHOT.jar
     0 Wed Mar 26 15:51:06 MSK 2014 META-INF/
   121 Wed Mar 26 15:51:04 MSK 2014 META-INF/MANIFEST.MF
     0 Wed Mar 26 14:29:58 MSK 2014 com/
     0 Wed Mar 26 14:29:58 MSK 2014 com/bigdata/
     0 Wed Mar 26 14:29:58 MSK 2014 com/bigdata/hadoop/
  3992 Fri Mar 21 17:29:22 MSK 2014 hive-site.xml
  4093 Wed Mar 26 14:29:58 MSK 2014 com/bigdata/hadoop/FieldCounts.class
  2961 Wed Mar 26 14:29:58 MSK 2014 com/bigdata/hadoop/FieldCounts$Reduce.class
  1621 Wed Mar 26 14:29:58 MSK 2014 com/bigdata/hadoop/TableFieldValueKey.class
  4186 Wed Mar 26 14:29:58 MSK 2014 com/bigdata/hadoop/FieldCounts$Map.class
     0 Wed Mar 26 15:51:06 MSK 2014 META-INF/maven/
     0 Wed Mar 26 15:51:06 MSK 2014 META-INF/maven/com.bigdata.hadoop/
     0 Wed Mar 26 15:51:06 MSK 2014 META-INF/maven/com.bigdata.hadoop/FieldCounts/
  1030 Wed Mar 26 14:28:22 MSK 2014 META-INF/maven/com.bigdata.hadoop/FieldCounts/pom.xml
   123 Wed Mar 26 14:30:02 MSK 2014 META-INF/maven/com.bigdata.hadoop/FieldCounts/pom.properties

What is wrong? Should I put Map and Reduce classes in separate files?
MapReduce code:
package com.bigdata.hadoop;

import java.io.IOException;
import java.util.*;

import org.apache.hadoop.conf.*;
import org.apache.hadoop.io.*;
import org.apache.hadoop.mapreduce.*;
import org.apache.hadoop.util.*;
import org.apache.hcatalog.mapreduce.*;
import org.apache.hcatalog.data.*;
import org.apache.hcatalog.data.schema.*;
import org.apache.log4j.Logger;

public class FieldCounts extends Configured implements Tool {

    public static class Map extends Mapper<WritableComparable, HCatRecord, TableFieldValueKey, IntWritable> {

        static Logger logger = Logger.getLogger("com.foo.Bar");

        static boolean firstMapRun = true;
        static List<String> fieldNameList = new LinkedList<String>();
        /**
         * Return a list of field names not containing `id` field name
         * @param schema
         * @return
         */
        static List<String> getFieldNames(HCatSchema schema) {
            // Filter out `id` name just once
            if (firstMapRun) {
                firstMapRun = false;
                List<String> fieldNames = schema.getFieldNames();
                for (String fieldName : fieldNames) {
                    if (!fieldName.equals("id")) {
                        fieldNameList.add(fieldName);
                    }
                }
            } // if (firstMapRun)
            return fieldNameList;
        }

        @Override
      protected void map( WritableComparable key,
                          HCatRecord hcatRecord,
                          //org.apache.hadoop.mapreduce.Mapper
                          //<WritableComparable, HCatRecord, Text, IntWritable>.Context context)
                          Context context)
            throws IOException, InterruptedException {

            HCatSchema schema = HCatBaseInputFormat.getTableSchema(context.getConfiguration());

           //String schemaTypeStr = schema.getSchemaAsTypeString();
           //logger.info("******** schemaTypeStr ********** : "+schemaTypeStr);

           //List<String> fieldNames = schema.getFieldNames();
            List<String> fieldNames = getFieldNames(schema);
            for (String fieldName : fieldNames) {
                Object value = hcatRecord.get(fieldName, schema);
                String fieldValue = null;
                if (null == value) {
                    fieldValue = "<NULL>";
                } else {
                    fieldValue = value.toString();
                }
                //String fieldNameValue = fieldName+"."+fieldValue;
                //context.write(new Text(fieldNameValue), new IntWritable(1));
                TableFieldValueKey fieldKey = new TableFieldValueKey();
                fieldKey.fieldName = fieldName;
                fieldKey.fieldValue = fieldValue;
                context.write(fieldKey, new IntWritable(1));
            }

        }
    }

    public static class Reduce extends Reducer<TableFieldValueKey, IntWritable,
                                       WritableComparable, HCatRecord> {

        protected void reduce( TableFieldValueKey key,
                               java.lang.Iterable<IntWritable> values,
                               Context context)
                               //org.apache.hadoop.mapreduce.Reducer<Text, IntWritable,
                               //WritableComparable, HCatRecord>.Context context)
            throws IOException, InterruptedException {
            Iterator<IntWritable> iter = values.iterator();
            int sum = 0;
            // Sum up occurrences of the given key
            while (iter.hasNext()) {
                IntWritable iw = iter.next();
                sum = sum + iw.get();
            }

            HCatRecord record = new DefaultHCatRecord(3);
            record.set(0, key.fieldName);
            record.set(1, key.fieldValue);
            record.set(2, sum);

            context.write(null, record);
        }
    }

    public int run(String[] args) throws Exception {
        Configuration conf = getConf();
        args = new GenericOptionsParser(conf, args).getRemainingArgs();

        // To fix Hadoop "META-INFO" (http://stackoverflow.com/questions/17265002/hadoop-no-filesystem-for-scheme-file)
        conf.set("fs.hdfs.impl",
                org.apache.hadoop.hdfs.DistributedFileSystem.class.getName());
        conf.set("fs.file.impl",
                org.apache.hadoop.fs.LocalFileSystem.class.getName());

        // Get the input and output table names as arguments
        String inputTableName = args[0];
        String outputTableName = args[1];
        // Assume the default database
        String dbName = null;

        Job job = new Job(conf, "FieldCounts");

        HCatInputFormat.setInput(job,
                InputJobInfo.create(dbName, inputTableName, null));
        job.setJarByClass(FieldCounts.class);
        job.setMapperClass(Map.class);
        job.setReducerClass(Reduce.class);

        // An HCatalog record as input
        job.setInputFormatClass(HCatInputFormat.class);

        // Mapper emits TableFieldValueKey as key and an integer as value
        job.setMapOutputKeyClass(TableFieldValueKey.class);
        job.setMapOutputValueClass(IntWritable.class);

        // Ignore the key for the reducer output; emitting an HCatalog record as
        // value
        job.setOutputKeyClass(WritableComparable.class);
        job.setOutputValueClass(DefaultHCatRecord.class);
        job.setOutputFormatClass(HCatOutputFormat.class);

        HCatOutputFormat.setOutput(job,
                OutputJobInfo.create(dbName, outputTableName, null));
        HCatSchema s = HCatOutputFormat.getTableSchema(job);
        System.err.println("INFO: output schema explicitly set for writing:"
                + s);
        HCatOutputFormat.setSchema(job, s);
        return (job.waitForCompletion(true) ? 0 : 1);
    }

    public static void main(String[] args) throws Exception {
        String classpath = System.getProperty("java.class.path");
        System.out.println("*** CLASSPATH: "+classpath);
        int exitCode = ToolRunner.run(new FieldCounts(), args);
        System.exit(exitCode);
    }
}

A: As I found out the problem was in directory permissions where MapReduce jar was located. This jar was built in a home directory of a regular, not hdfs user. As long as this MRD job outputs results of its work directly into Hive table, it should be run under hdfs user. In case such a job is run under regular user it has no permission to write data into Hive table!
On the other hand a home directory of a regular user in CentOS has 700 permissions. So when you run hadoop jar ... command under user different from the user owning this home directory access to MRD jar gets denied somewhere in the process of loading classes by Hadoop. That's why under hdfs user this job results in java.lang.RuntimeException: java.lang.ClassNotFoundException: Class com.bigdata.hadoop.MyMap not found.
Recursively changing permission of home directory from 700 to 755 where MRD jar was built solves this problem.
Yet a more important problem remains: How to run a job under regular user so it has permission to write data into a Hive table?

A: I've found the following
Set hadoop system user for client embedded in Java webapp
that allowed me to connect as the expected hadoop user, but jar is not yet uploaded nor executed... ClassNotFound remains


text:
Q: GCS file streaming using dataflow(apachebeam python) I have a GCS where i get file every minute.I have created a streaming dataflow by using apache beam python sdk.i created pub/sub topic for input gcs bucket and output gcs bucket.my dataflow is streaming yet my output is not getting stored in the output bucket.this is my following code ,
from __future__ import absolute_import

    import os
    import logging
    import argparse
    from google.cloud import language
    from google.cloud.language import enums
    from google.cloud.language import types
    from datetime import datetime
    import apache_beam as beam
    from apache_beam.options.pipeline_options import PipelineOptions
    from apache_beam.options.pipeline_options import SetupOptions
    from apache_beam.options.pipeline_options import GoogleCloudOptions
    from apache_beam.options.pipeline_options import StandardOptions
    from apache_beam.io.textio import ReadFromText, WriteToText

    #dataflow_options = ['--project=****','--job_name=*****','--temp_location=gs://*****','--setup_file=./setup.py']
    #dataflow_options.append('--staging_location=gs://*****')
    #dataflow_options.append('--requirements_file ./requirements.txt')
    #options=PipelineOptions(dataflow_options)
    #gcloud_options=options.view_as(GoogleCloudOptions)

    # Dataflow runner
    #options.view_as(StandardOptions).runner = 'DataflowRunner'
    #options.view_as(SetupOptions).save_main_session = True

    def run(argv=None):
        """Build and run the pipeline."""
        parser = argparse.ArgumentParser()
        parser.add_argument(
            '--output_topic', required=True,
            help=('Output PubSub topic of the form '
                '"projects/***********".'))
        group = parser.add_mutually_exclusive_group(required=True)
        group.add_argument(
            '--input_topic',
            help=('Input PubSub topic of the form '
                '"projects/************".'))
        group.add_argument(
            '--input_subscription',
            help=('Input PubSub subscription of the form '
                '"projects/***********."'))
        known_args, pipeline_args = parser.parse_known_args(argv)

      # We use the save_main_session option because one or more DoFn's in this
      # workflow rely on global context (e.g., a module imported at module level).
        pipeline_options = PipelineOptions(pipeline_args)
        pipeline_options.view_as(SetupOptions).save_main_session = True
        pipeline_options.view_as(StandardOptions).streaming = True
        p = beam.Pipeline(options=pipeline_options)

        # Read from PubSub into a PCollection.
        if known_args.input_subscription:
            messages = (p
                        | beam.io.ReadFromPubSub(
                            subscription=known_args.input_subscription)
                        .with_output_types(bytes))
        else:
            messages = (p
                        | beam.io.ReadFromPubSub(topic=known_args.input_topic)
                        .with_output_types(bytes))

        lines = messages | 'decode' >> beam.Map(lambda x: x.decode('utf-8'))

        class Split(beam.DoFn):
            def process(self,element):
                element = element.rstrip("\n").encode('utf-8')
                text = element.split(',')
                result = []
                for i in range(len(text)):
                    dat = text[i]
                    #print(dat)
                    client = language.LanguageServiceClient()
                    document = types.Document(content=dat,type=enums.Document.Type.PLAIN_TEXT)
                    sent_analysis = client.analyze_sentiment(document=document)
                    sentiment = sent_analysis.document_sentiment
                    data = [
                    (dat,sentiment.score)
                    ]
                    result.append(data)
                return result

        class WriteToCSV(beam.DoFn):
            def process(self, element):
                return [
                    "{},{}".format(
                        element[0][0],
                        element[0][1]
                    )
                ]

        Transform = (lines
                    | 'split' >> beam.ParDo(Split())
                    | beam.io.WriteToPubSub(known_args.output_topic)
        )
        result = p.run()
        result.wait_until_finish()

    if __name__ == '__main__':
      logging.getLogger().setLevel(logging.INFO)
      run()

what am i doing wrong please someone explain it to me .

A: WriteToPubSub writes data to a PubSub topic, not to a GCS bucket. What you want to do is, perhaps, use WriteToText, or a DoFn that writes your data to the bucket using apache_beam.io.filesystems.
An extra note is that it doesn't look like your WriteToCsv transform is used anywhere.


text:
Q: how to use glide.js carousel with popup modal? I'm trying to create a carousel that when clicked will open a popup modal containing another carousel (bigger resolution) using glide.js. so I'm trying to build a simple model first, which is a button to open a popup modal containing the big carousel. but I'm facing these problems:

*

*the DOMs keep exceeding the viewport's height

*when the styles and script for the popup modal is applied, it became like the screenshot below (the image is broken and the browser's scrollbar exceeds the computer monitor)

here's my code
<!DOCTYPE html>

    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <link rel="stylesheet" href="/assets/css/reset.css">
    <link rel="stylesheet" href="/assets/css/glide.core.min.css">
    <link rel="stylesheet" href="/assets/css/glide.theme.min.css">
    <link rel="stylesheet" href="/assets/css/glide_style.css">
    <link rel="stylesheet" href="/assets/css/modal_style.css">

<button id="myBtn">Open Modal</button>

    ×

                <button class="glide__arrow glide__arrow--left" data-glide-dir="<">prev</button>
                <button class="glide__arrow glide__arrow--right" data-glide-dir=">">next</button>

reset.css
/* http://meyerweb.com/eric/tools/css/reset/
   v2.0 | 20110126
   License: none (public domain)
*/

html, body, div, span, applet, object, iframe,
h1, h2, h3, h4, h5, h6, p, blockquote, pre,
a, abbr, acronym, address, big, cite, code,
del, dfn, em, img, ins, kbd, q, s, samp,
small, strike, strong, sub, sup, tt, var,
b, u, i, center,
dl, dt, dd, ol, ul, li,
fieldset, form, label, legend,
table, caption, tbody, tfoot, thead, tr, th, td,
article, aside, canvas, details, embed,
figure, figcaption, footer, header, hgroup,
menu, nav, output, ruby, section, summary,
time, mark, audio, video {
    margin: 0;
    padding: 0;
    border: 0;
    font-size: 100%;
    font: inherit;
    vertical-align: baseline;
}
/* HTML5 display-role reset for older browsers */
article, aside, details, figcaption, figure,
footer, header, hgroup, menu, nav, section {
    display: block;
}
body {
    line-height: 1;
}
ol, ul {
    list-style: none;
}
blockquote, q {
    quotes: none;
}
blockquote:before, blockquote:after,
q:before, q:after {
    content: '';
    content: none;
}
table {
    border-collapse: collapse;
    border-spacing: 0;
}

glide_style.css
html, body {
    height: 100%;
}

.glide__arrow {
    color: #a0a0a0 !important;
}

.glide-container {
    height: 100vh;
    width: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
}

.glide__slide {
    display: flex;
    justify-content: center;
    margin-top: auto;
    margin-bottom: auto;
}

modal_style.css
body {font-family: Arial, Helvetica, sans-serif;}

/* The Modal (background) */
.modal {
  display: none; /* Hidden by default */
  position: fixed; /* Stay in place */
  z-index: 1; /* Sit on top */
  padding-top: 100px; /* Location of the box */
  left: 0;
  top: 0;
  width: 100%; /* Full width */
  height: 100%; /* Full height */
  overflow: auto; /* Enable scroll if needed */
  background-color: rgb(0,0,0); /* Fallback color */
  background-color: rgba(0,0,0,0.4); /* Black w/ opacity */
}

/* Modal Content */
.modal-content {
  background-color: #fefefe;
  margin: auto;
  padding: 20px;
  border: 1px solid #888;
  width: 80%;
  position: relative;
}

/* The Close Button */
.close {
  color: #aaaaaa;
  float: right;
  font-size: 28px;
  font-weight: bold;
  position: absolute;
  top: 20px;
  right: 20px;
}

.close:hover,
.close:focus {
  color: #000;
  text-decoration: none;
  cursor: pointer;
}

modal_script.js
// Get the modal
var modal = document.getElementById("myModal");

// Get the button that opens the modal
var btn = document.getElementById("myBtn");

// Get the  element that closes the modal
var span = document.getElementsByClassName("close")[0];

// When the user clicks the button, open the modal
btn.onclick = function() {
  modal.style.display = "block";
}

// When the user clicks on  (x), close the modal
span.onclick = function() {
  modal.style.display = "none";
}

// When the user clicks anywhere outside of the modal, close it
window.onclick = function(event) {
  if (event.target == modal) {
    modal.style.display = "none";
  }
}

if there's a more suitable and easier library for this case, please recommend it to me..


text:
Q: Distribute a number equally in ruby I'm trying to distribute a number equally into an array of a given size. If I have a number 10 and an array size of 3, then I should distribute it into an array as below:
x = [4, 3, 3]

Later if I want to increment the number by 1, then I should pick up (one of) the lowest number(s) from the array, and update them one after another.
x = [4, 4, 3]

Later if I want to increment the number by 2, then I should update the array as below:
x = [5, 4, 4]

UPDATE:
I was able to do the first part
def split_into n, p
  [n / p + 1] * (n % p) + [n / p] * (p - n % p)
end

split_into(10, 3) #=> [4, 3, 3]

A: A simple way, repeat finding and incrementing the smallest number:
n.times { x[x.index(x.min)] += 1 }

Demo:
x = [0, 0, 0]
n = 10

n.times { x[x.index(x.min)] += 1 }
x #=> [4, 3, 3]

n = 4
n.times { x[x.index(x.min)] += 1 }
x #=> [5, 5, 4]

Another simple way, reusing your existing method, faster in case n is large:
x = split_into(x.sum + n, x.size)

A: If you're trying to split something into even groups, use Rails' in_groups_of:
(1..10).to_a.in_groups_of(3) #=> [[1, 2, 3], [4, 5, 6], [7, 8, 9], [10, nil, nil]]

You can also specify not to nil-pad the end by providing a second parameter of false.
If you really want to know the size of the groups, you can get it using in_groups (slightly different than in_groups_of):
(1..10).to_a.in_groups(3, false).map(&:size) #=> [4, 3, 3]

A: You can calculate the quotient and remainder via divmod:
q, r = 10.divmod(3)
#=> [3, 1]

And create the corresponding array via Array.new:
Array.new(3) { |i| i < r ? q + 1 : q }
#=> [4, 3, 3]

As a method:
def split_into(n, p)
  q, r = n.divmod(p)
  Array.new(p) { |i| i < r ? q + 1 : q }
end

a = split_into(10, 3)
#=> [4, 3, 3]

To "increment" the array by 1, you could add 1 it to the array's sum and call split_into again:
a = split_into(a.sum + 1, a.size)
#=> [4, 4, 3]

same for 2:
a = split_into(a.sum + 2, a.size)
#=> [5, 4, 4]


text:
Q: Shopware 6 JEST unit test: setup failed with configuration error 'Could not locate module' I try to run a simple test with jest in Shopware 6 custom plugin application.
The test failed with configuration error "Could not locate module"

 FAIL  component/src/test/sum.spec.js
  ● Test suite failed to run

    Configuration error:

    Could not locate module @shopware-ag/admin-extension-sdk/es/data/Criteria mapped as:
    @shopware-ag/admin-extension-sdk/umd$1.

    Please check your configuration for these entries:
    {
      "moduleNameMapper": {
        "/^@shopware-ag\/admin-extension-sdk\/es(.*)$/": "@shopware-ag/admin-extension-sdk/umd$1"
      },
      "resolver": undefined
    }

    > 1 | import Criteria from '@shopware-ag/admin-extension-sdk/es/data/Criteria';
        | ^
      2 |
      3 | // eslint-disable-next-line sw-deprecation-rules/private-feature-declarations
      4 | export default Criteria;

      at createNoMappedModuleFoundError (../node_modules/jest-resolve/build/resolver.js:759:17)
      at Object.<anonymous> (../../../../../../../../../src/Administration/Resources/app/administration/src/core/data/criteria.data.ts:1:1)
      at Object.<anonymous> (../../../../../../../../../src/Administration/Resources/app/administration/src/core/data/index.js:2:1)
      at Object.<anonymous> (../../../../../../../../../src/Administration/Resources/app/administration/src/core/shopware.ts:34:1)
      at Object.<anonymous> (../node_modules/@shopware-ag/jest-preset-sw6-admin/@tool/setup-env-for-shopware.js:8:18)
...

The file @shopware-ag/admin-extension-sdk/es/data/Criteria (Criteria.d.ts) is present.
// package.json
...
  ...
  "dependencies": {
    "@babel/preset-typescript": "^7.18.6",
    "@babel/runtime": "^7.20.13",
    "@shopware-ag/admin-extension-sdk": "^3.0.3"
  },
  "devDependencies": {
    "@babel/core": "^7.20.12",
    "@babel/plugin-proposal-decorators": "^7.20.13",
    "@babel/plugin-proposal-export-namespace-from": "^7.18.9",
    "@babel/plugin-proposal-function-sent": "^7.18.6",
    "@babel/plugin-proposal-json-strings": "^7.18.6",
    "@babel/plugin-proposal-numeric-separator": "^7.18.6",
    "@babel/plugin-proposal-throw-expressions": "^7.18.6",
    "@babel/plugin-syntax-dynamic-import": "^7.8.3",
    "@babel/plugin-syntax-import-meta": "^7.10.4",
    "@babel/plugin-transform-runtime": "^7.19.6",
    "@babel/preset-env": "^7.20.2",
    "@babel/register": "^7.18.9",
    "@shopware-ag/jest-preset-sw6-admin": "^4.0.1",
    "@vue/test-utils": "^2.2.10",
    "babel-jest": "^29.4.2",
    "jest": "^29.4.2",
    "jest-environment-jsdom": "^29.4.2"
  }
...

My jest config file:
const { join, resolve } = require('path');

process.env.ADMIN_PATH = resolve("../../../../../../../../src/Administration/Resources/app/administration/");

module.exports = {
    preset: '@shopware-ag/jest-preset-sw6-admin',
    globals: {
        // adminPath: process.env.ADMIN_PATH,
        adminPath: process.env.ADMIN_PATH,
        // projectRoot: process.env.PROJECT_ROOT,
    },

    rootDir: "./component/",

    moduleNameMapper: {
        '^test(.*)$': '<rootDir>/test$1',
        vue$: 'vue/dist/vue.common.dev.js',
        "uuid": require.resolve('uuid'),
    },
};

Questions

*

*Why does the mapping fail?

*Is there a dependency missing in my package.json?

I miss documentation about this.

Not yet a solution here, what I have done:

*

*re-setup using the Shopware instruction

*rewrite the jest.config.js:

const ADMIN_PATH = process.env.ADMIN_PATH = resolve(
    "../../../../../../../../src/Administration/Resources/app/administration/"
)

module.exports = {
    preset: "@shopware-ag/jest-preset-sw6-admin",
    globals: {
        adminPath: ADMIN_PATH,
    },
    moduleNameMapper: {
        "uuid": require.resolve('uuid'),
    },
};

*

*running test: same mapping error:

Could not locate module
   @shopware-ag/admin-extension-sdk/es/data/Criteria mapped as:
@shopware-ag/admin-extension-sdk/umd$1.

*

*debug the request: the mapping error comes from this script

custom/plugins/MyPlugin/src/Resources/app/administration/test/node_modules/@shopware-ag/jest-preset-sw6-admin/jest-preset.js

What i find out, the required imported script is a typescript which import another typescript:

*

*../../../../../../../../../src/Administration/Resources/app/administration/src/core/data/index.js:2:1):

import ChangesetGenerator from './changeset-generator.data';
import Criteria from './criteria.data';
...
export default {
    ChangesetGenerator,
    Criteria,
    ...
};

*

*../../../../../../../../src/Administration/Resources/app/administration/src/core/data/criteria.data.ts:
import Criteria from '@shopware-ag/admin-extension-sdk/es/data/Criteria'; // <---this import fails

// eslint-disable-next-line sw-deprecation-rules/private-feature-declarations
export default Criteria;

No glue if the typescript context is relevant, but the further required import of js file is imported without error

A: Solution in short:
// ~/custom/plugin/myPlugin/src/Resources/app/administration/jest.config

const path = require('path');
const resolve = path.resolve;

const adminPath = process.env.ADMIN_PATH = resolve(
    "/path/to.../src/Administration/Resources/app/administration"
);

module.exports = {
    testEnvironmentOptions: {
        customExportConditions: ["node", "node-addons"],
    },

    preset: '\@shopware-ag/jest-preset-sw6-admin',
    globals: {
        adminPath: adminPath,
    },
    moduleNameMapper: {
        '^\@shopware-ag/admin-extension-sdk/es(.*)$': adminPath  + '/node_modules/\@shopware-ag/admin-extension-sdk/umd$1',
        "uuid": require.resolve('uuid'),
    },
    testMatch: [
        '<rootDir>/test/**/*.spec.js',
    ],
};

Extended Answer:
I followed the poor Shopware documentation and the unmentioned Shopware Default Jest Preset (at least I couldn't find it). At this way i was guide to install vue-test-utils with npm install --save-dev @vue/test-utils.
This command install the newest version of vue-test-utils (version 2.+), but Shopware 6 (include the actual Version 6.5)  is using "@vue/test-utils": "1.3.3" until today. Result: Conflicts.
After installing the corresponding vue-test-utils and configuration with this hint, the tests still don't work:
...
 globals: {
        adminPath: '<file-path-to-sw6-administration>', // required, e.g. /www/sw6/platform/src/Administration/Resources/app/administration
    }

The right mapping should be:
moduleNameMapper: {
        '^\@shopware-ag/admin-extension-sdk/es(.*)$': adminPath  + '/node_modules/\@shopware-ag/admin-extension-sdk/umd$1',
    },

With this configuration i was able to work.
Summary: Be carefull using the provided Shopware documentation.


text:
Q: Django Channels code is working on Chrome but not Firefox I am writing a chat application using Django and Channels (new websocket implementation for Django). Users first enter a wait room, until at least 3 other people have joined, then they are directed to a chat room. The code works fine for Chrome, but is not working correctly for Firefox. Here is how it works:

*

*On a new connect to the channel/websocket the server checks to see if at least three people are in the wait room (in consumers.py).

*If at least three people are present it broadcasts a message to the channel/websocket using the Group function telling them to redirect.

*The message is received by the clients and it executes a redirection in javascript.

Here are the steps I've taken to debug the problem:

*

*The code works in browsers other than Firefox (e.g. Chrome).

*The code works if the first two clients arriving to the wait room are Firefox and the last one (that triggers the server) is Chrome. It redirects all three clients.

*If the first two clients are Chrome and the last client (that triggers the server) is Firefox it redirects the Chrome clients but not the Firefox client.

*The problem is unlikely to be with the javascript running the redirection because replacing the code with a simple alert message (upon the client receiving the Group statement) is also not working in Firefox (but does work in Chrome). It is as if the Firefox client never receives the Group message when it is the client that triggers the server.

*The chat uses channels and works on all browsers including Firefox. It successfully connects, sends messages, receives messages, and disconnects.

Based on these debugging steps I think something is going wrong when Firefox instigates the server code that executes the Group redirect. Do you have any suggestions for what might be going wrong? Do you have any suggestions that would help identify the problem?
Here is the code in consumers.py that I think is causing the problem:
@channel_session_user_from_http
@channel_session
def wait_connect(message):
    try:
        wait_room, created = WaitRoom.objects.get_or_create(title=title)

    except WaitRoom.DoesNotExist:
        log.debug('ws room does not exist title=%s', title)
        return

    Group('wait-'+title, channel_layer=message.channel_layer).add(message.reply_channel)
    wait_user,created = wait_room.users.get_or_create(user=message.user)

    userlist = WaitUser.objects.filter(wait_room=wait_room,is_active=1)

    if len(userlist)>=3:
        t = {t['url']='redirecturl'}
        Group('wait-'+title, channel_layer=message.channel_layer).send({'text': json.dumps(t)})

Here is the javascript code that is executing the redirect:
$(function() {

var ws_scheme = window.location.protocol == "https:" ? "wss" : "ws";
var chatsock = new ReconnectingWebSocket(ws_scheme + '://' + window.location.host  + window.location.pathname);

chatsock.onmessage = function(message) {
    var data = JSON.parse(message.data);

    window.location.replace(data.url);

};});


text:
Q: Equilibrium concentration of point defects in solids at sufficiently elevated temperature Equilibrium concentration of point defects in solids is defined as $\chi=\exp(\frac{\Delta s}{k_B})\exp(\frac{-\Delta h}{k_BT})$. At high temperatures, may be even higher than melting temperature of the solid, does the entropy become undefined meaning there will be no equilibrium concentration for point defects?

A: Mathematically, the equation can yield a result at any temperature. But, since the concept of point defect makes sense only in a crystal, in a liquid the calculation yields a number with no meaning. Like applying the formula to T < 0.
Also, the equilibrium concentration is not "defined" by your equation.


text:
Q: How t extract last part of a text in python I have a column of  strings in abcd@xxxxx@yyyyy@zzzz format,in a dataframe column . I want to iterate over all the values of the column, split the value using delimiter and extract the last part in a newly created column . To do so, I tried the below approach :
data['Issues']=data.Summary.str.split('@')[-1]
Where, 'Issues' is the newly created column and 'Summary' is the column I am iterating over. However doing so , I am getting the below error:
KeyError: -1
Can anyone please help with the solution ?

A: No need for regex here:
result = input_str.split('@')[-1]


text:
Q: Measuring probability that 2 sample originate from the same population I have two dataset that i want to compare.
each dataset contain the weight of 10 different person measured for 3 different day.
I am interested  in measuring the probabily that the two sample originate from the same population.
People seem to suggest doing a Kolmogorov-Smirnov test but i need a measurement.
I was thinking doing the EMD to compare the distribution for each day
EMD(dataset1-day1,dataset2-day1) + EMD(dataset1-day2,dataset2-day2) + EMD(dataset1-day3,dataset2-day3)
But i could probably take each person as a 3d datapoint and do the EMD in 3d.
One other possibility was to do the Hausdorff distance but doing the average of the distance for each point instead of taking the maximum distance.
What are the main difference between the two technique.


text:
Q: Android Location update is happening twice I want to run location update as a service. Now I can able to run the service correctly but the location updation is happening twice, Here is the code,
AndroidManifest.xml
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />

 <service
    android:name=".services.LocationService"
    android:icon="@drawable/ic_location"
    android:label="Location Service">
    <intent-filter>
        <action android:name="android.service.notification.service" />
    </intent-filter>
</service>

In the Activity Class we are using startLocationService() to start the service and stopLocationService() to stop the service, Also created a Broadcast Receiver to get the location updation on the Activity Calss.
private BroadcastReceiver broadcastReceiver;
private Intent mLocationServiceIntent;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_navigtaion_drawer);

    AppController.getInstance().activityResumed();
    broadcastReceiver = createBroadcastReceiver();
    registerReceiver(broadcastReceiver, new IntentFilter(getPackageName()));

    if (!Permissions.hasLocationPermission(this)) {
        Permissions.requestLocationPermission(this, PermissionKeys.LOCATION_REQUEST_HOME_ON_RESUME);
    } else
        startLocationService();

}

private BroadcastReceiver createBroadcastReceiver() {
    return new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
           if (intent.hasExtra(LocationService.LOCATION_UPDATED)) {
                Bundle b = intent.getExtras();
                if (b != null) {
                    Location mCurrentLocation = (Location) b.get(LocationService.LOCATION_UPDATED);
                }
            }
        }
    };
}

   //Function To Start the Service
   public void startLocationService() {
        if (mLocationServiceIntent == null)
            mLocationServiceIntent = new Intent(this, LocationService.class);
        startService(mLocationServiceIntent);
    }

    //Function To Stop the Service
    public void stopLocationService() {
        if (mLocationServiceIntent != null)
            stopService(mLocationServiceIntent);
    }

LocationService.java
public class LocationService extends Service implements LocationListener, GoogleApiClient.ConnectionCallbacks, GoogleApiClient.OnConnectionFailedListener {
    public static final String LOCATION_UPDATED = "LocationUpdated";
    public static final String LATITUDE = "Latitude";
    public static final String LONGITUDE = "Longitude";

    LocationRequest mLocationRequest;
    GoogleApiClient mGoogleApiClient;

    private static final String TAG = "###LocationService:: ";
    private static final int LOCATION_INTERVAL = 15000;
    private static final int FASTEST_INTERVAL = 10000;
    private static final float LOCATION_DISTANCE = 7f;

    @Override
    public void onCreate() {
        if (isGooglePlayServicesAvailable()) {
            mLocationRequest = new LocationRequest();
            mLocationRequest.setInterval(LOCATION_INTERVAL);
            mLocationRequest.setFastestInterval(FASTEST_INTERVAL);
            mLocationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);
            //mLocationRequest.setSmallestDisplacement(10.0f);  /* min dist for location change, here it is 10 meter */
            mGoogleApiClient = new GoogleApiClient.Builder(this)
                    .addApi(LocationServices.API)
                    .addConnectionCallbacks(this)
                    .addOnConnectionFailedListener(this)
                    .build();

            mGoogleApiClient.connect();
        }
    }

    //Check Google play is available or not
    private boolean isGooglePlayServicesAvailable() {
        int status = GooglePlayServicesUtil.isGooglePlayServicesAvailable(getApplicationContext());
        return ConnectionResult.SUCCESS == status;
    }

    @Override
    public void onConnected(Bundle bundle) {
        Log.e(TAG, "Connected");
        startLocationUpdates();
    }

    @Override
    public void onConnectionSuspended(int i) {
        Log.e(TAG, "Connection suspended");
    }

    protected void startLocationUpdates() {
        Log.e(TAG, "Start Location Updates");
        try {
            int permissionCheck = ContextCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION);
            if (permissionCheck == PackageManager.PERMISSION_GRANTED) {
                PendingResult<Status> pendingResult = LocationServices.FusedLocationApi.requestLocationUpdates(mGoogleApiClient, mLocationRequest, this);
            }
        } catch (IllegalStateException e) {
        }
    }

    @Override
    public void onLocationChanged(Location location) {
        if (location != null) {
            Log.e(TAG, "Location Changed : " + location.getLatitude() + "," + location.getLongitude());
            Intent intent = new Intent(getPackageName());
            intent.putExtra(LOCATION_UPDATED, location);
            sendBroadcast(intent);

        }

    }

   /* LocationListener[] mLocationListeners = new LocationListener[]{
            new LocationListener(LocationManager.GPS_PROVIDER),
            new LocationListener(LocationManager.NETWORK_PROVIDER)
    };*/

    @Override
    public IBinder onBind(Intent arg0) {
        return null;
    }

    @Override
    public int onStartCommand(Intent intent, int flags, int startId) {
        super.onStartCommand(intent, flags, startId);
        return START_STICKY;
    }

    @Override
    public void onConnectionFailed(@NonNull ConnectionResult connectionResult) {
        Log.e(TAG, "onConnectionFailed:: "+connectionResult.getErrorMessage());
    }
}

A: I have fixed this issue by adding a condition checking before start the service,
My updated startLocationService() function is like,
//Function To Start the Service
   public void startLocationService() {
        if (mLocationServiceIntent == null)
            mLocationServiceIntent = new Intent(this, LocationService.class);
        if(!isServiceRunning(HomeScreenActivity.this, LocationService.class)) {
            startService(mLocationServiceIntent);
        }
    }

Here is the function to check if the service is already running or not.
//This function is to check the service is already running or not
    public boolean isServiceRunning(Context context, Class<?> serviceClass) {
        ActivityManager manager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
        for (ActivityManager.RunningServiceInfo service : manager.getRunningServices(Integer.MAX_VALUE)) {
            if (serviceClass.getName().equals(service.service.getClassName())) {
                Log.e("ServiceRunning", serviceClass.getSimpleName() + " is alredy running");
                return true;
            }
        }
        return false;
    }


text:
Q: I am unable to set my wordpress menu for mobile version I have two menus, one is for mobile view, and other is for desktop view. I am changing into wordpress dynamic menu. But mobile menu is not working properly, it not showing toggle button and proper styles of the menu. I have the following codes in html:

    <form action="#" name="search" class="col-xs-12">
    <input type="text" name="search" placeholder="Type and Hit Enter">
    </form>

        WorkHub

               Home

               About Us

                Services

Services

Service Detail

                    gallery

                    News

Blog

Blog Detail

                    Contact

Home

 About Us

Services

Services

Service Detail

 gallery

News

Blog

Blog Detail

Contact

And my dynamic code is as follows:

                <form action="#" name="search" class="col-xs-12">
                    <input type="text" name="search" placeholder="Type and Hit Enter">
                </form>

                <a href="<?php echo esc_url( home_url( '/' ) ); ?>"><?php bloginfo('site-title'); ?>

            <?php
            wp_nav_menu(array(
            'theme_location' => 'primary',
            'container' => 'div',
            'container_class' => 'menu-wrap col-md-8',
            'menu_class' => 'menu'
            ));
            ?>

              <?php
            wp_nav_menu(array(
            'theme_location' => 'primary',
            'container' => 'nav',
            'container_class' => 'mobile-nav',
            ));
            ?>

So what can I do to get the mobile menu in proper way. Thanking you.

A: Try this:
<?php
 wp_nav_menu(array(
 'theme_location' => 'primary',
 'container' => 'div',
 'container_id' => 'menu-wrap col-md-8',
 'menu_class' => 'menu'
  ));
  ?>


text:
Q: Fuzzy String Matching using Python I have a training dataset for eg.
Letter    Word
A         Apple
B         Bat
C         Cat
D         Dog
E         Elephant

and I need to check the dataframe such as
AD    Apple Dog
AE    Applet Elephant
DC    Dog Cow
EB    Elephant Bag
AED   Apple Elephant Dog
D     Door
ABC   All Bat Cat

the instances AD,AE,EB are almost accurate (Apple and Applet are considered closer to each other, similar for Bat and Bag) but DC doesn't match.
Output Required:
Letters    Words               Status
AD         Apple Dog           Accept
AE         Applet Elephant     Accept
DC         Dog Cow             Reject
EB         Elephant Bag        Accept
AED        Apple Elephant Dog  Accept
D          Door                Reject
ABC        All Bat Cat         Accept

ABC accepted because 2 of 3 words match.
The words accepted need to be matched 70% (Fuzzy Match). yet, threshold subject to change.
How can I find these matches using Python.

A: You can use thefuzz to solve your problem:
# Python env: pip install thefuzz
# Conda env: conda install thefuzz
from thefuzz import fuzz

THRESHOLD = 70

df2['Others'] = (df2['Letters'].agg(list).explode().reset_index()
                     .merge(df1, left_on='Letters', right_on='Letter')
                     .groupby('index')['Word'].agg(' '.join))

df2['Ratio'] = df2.apply(lambda x: fuzz.ratio(x['Words'], x['Others']), axis=1)
df2['Status'] = np.where(df2['Ratio'] > THRESHOLD, 'Accept', 'Reject')

Output:
>>> df2
  Letters               Words              Others  Ratio  Status
0      AD           Apple Dog           Apple Dog    100  Accept
1      AE     Applet Elephant      Apple Elephant     97  Accept
2      DC             Dog Cow             Dog Cat     71  Accept
3      EB        Elephant Bag        Elephant Bat     92  Accept
4     AED  Apple Elephant Dog  Apple Dog Elephant     78  Accept
5       D                Door                 Dog     57  Reject
6     ABC         All Bat Cat       Apple Cat Bat     67  Reject


text:
Q: Why are optical disc drives slower than hard disk drives? I know that hard disks have faster access times and transfer rates and when I searched why it appeared that:

*

*Hard disk drives spin much faster

*If filled with helium this can decrease the energy needed for spinning them and thus faster speeds

*You can store more data on a hard disk than on a similar sized optical disc so higher data density so the head won't have to travel as much distance as it has to with optical discs

*Optical discs (not all) store their data in spiral tracks

But why do HDDs spin faster, or why do their arms move faster? Why don't they manufacture the arm inside the optical disc drives to move at the speed of HDDs? Even magnetic tape drives are fast. (At least transfer rate, not access time.)
Also, can't the head go to a specific part of the spiral track and read from there?

A: Hard drives don't spin much faster.
HDD rotation speeds range from 4,200 rpm (super power friendly) to 10,000 rpm, with 5,400 and 7,200 rpm being the most common. 15,000 rpm server drives used to be on the market, but SSDs made them un-economical to produce so they haven't been manufactured since 2016.
A 48x CD-ROM drive spins the disc at 9,600 rpm, a 24x DVD-ROM drive spins the disc at 14,000 rpm, and a 16x BD-ROM drive spins the disc at 13,000 rpm.
So it's not a lower spin rate at all; optical discs simply have a lower data density, so the head sees less data per revolution, and that's what limits transfer rates. And they have lower data density because... well, they're very different technologies, so it's hard to make a fair comparison, but a large part of what lets hard drives store bits in such a small area is the fact that the head sits mere nanometers away from the platter surface, which is possible because everything is carefully constructed and then sealed in an airtight container. Optical discs are cheap, removable, and prone to getting dirty and scratched, so all of the tolerances have to be much bigger.

A: This isn't  directly related to the question but it'll help you understand the answers here and why HDD has to be sealed, which is a point repetitively mentioned in the various answers here.
First, its worth pointing out how incredibly small the read/write head is. I thought it was big and couldn't understand how it can "crash" to a dust particle.
So to read and write the magnetic information on the hard disk, the read/write head of the HDD is positioned incredibly close to the platter. It floats less than 0.1 microns over the surface of the platter. A micron (or micrometer) is one-millionth of a meter, meaning that the read/write head is less than 1/10th of a millionth of a meter from the platter's surface.
A tiny piece of dust can make the read-write head bounce up and down, crashing into the platter and damaging its magnetic material. A head crash often causes catastrophic damage to a hard drive all you need to imagine is lowering something metallic onto a circular disk that is spinning at thousands of rotations per minute. Even the slightest impact is going to cause significant damage sending platter debris across the surface.
To illustrate this, this picture shows a comparison of the sizes of a read/write head, an average dust particle (which is 2.5 microns), and an average human hair (which is 50 microns). In looking at the differences in size, it is easy to see how a simple piece of dust or hair on a platter could cause the hard disk to crash, and why the internal components are sealed inside the hard disk assembly.

Resources: https://www.dataclinic.co.uk/what-is-a-head-crash-hard-disk-drive-information/
https://www.sciencedirect.com/topics/computer-science/magnetic-hard-disk
Also from a deleted discussion room by John:
Platters in small drives are often glass, not metal, but contacting the magnetic coating in either case damages it. Remember a hard drive is meant to be read and written thousands of times. No read only CD (most) can do this at all and any writeable CD is not good for many thousands of writes. Again, the two devices (CD and HDD) are as different as night is to day.

A: There are two separate questions: latency and throughput.
Seek time
Optical drives have random seek times around 100 ms, whereas hard drives are around 10 ms - why is this?
An optical read/write head consists of a laser, detector, mirrors, lens, and multiple voice coils to position the head/lens for tracking/focusing. This entire assembly has a number of parts and is relatively heavy. The entire head assembly moves on a worm gear.

A hard disk head consists of a tiny GMR sensor for reading and coil for writing. The rest of it is the plastic slider and metal arm; the whole assembly is relatively light. The head is moved by a powerful voice coil. This is why seeking is fast.

Transfer rate
CD drives top out at about 10 MB/s. DVD drives top out at about 30 MB/s. Blu-ray drives top out at about 70 MB/s. Hard drives routinely hit 100~200 MB/s.
The two main factors that determine transfer rate are linear speed (metres per second) and linear density (bits per meter).
Desktop hard drives in the 3.5-inch form factor have a platter diameter of about 90 mm. Optical discs have a diameter of about 120 mm. I would rate these as "close enough" for comparison purposes.
Hard drives usually spin at 5400 RPM or 7200 RPM, with old enterprise models going up to 15000 RPM. Optical discs are spun at various speeds, depending on how quickly the host wants to read/write data (e.g. bulk read vs. streaming audio/video), how long the drive has been actively used, how much noise is desired, etc. But optical discs can spin up to about 10000 RPM in real drives without problems. So this is also in the same ballpark as HDD RPM.

Areal density is a huge factor to consider. Pretend for a moment that a CD is 1 GB and an HDD is 1000 GB and they have the same physical dimensions. Clearly, the HDD has 1000× the data density per area. As for linear density, the HDD is √1000 = 32 times denser than the CD. So if you position a head over the discs and make one full revolution, the HDD should read 32× more data than the CD, simply because more data is packed on each track. As we can see, this is why DVDs and BDs have higher transfer rates than CDs. But a 25-GB single-layer Blu-ray disc absolutely pales in comparison to even a cheap, basic 1 TB HDD. Though however, multi-layer optical discs and multi-side multi-platter hard disks make this calculation more complicated.
Bonus
To add insult to injury, my experience shows that after inserting an optical disc into a drive, it takes about 20 seconds to begin reading any user data on it. This start-up time is far worse than flash drives and even hard drives, and is especially painful when sifting through many discs.

A: While the other answers are correct, there is more.  Optical media is manufactured to be cheap and lightweight.  Its just a small piece of plastic.  It it not designed to spin at high speeds.  The faster it spins, imperfections in the plastic start to cause the plastic to warp.  The faster it spins, the more it warps.  This warping will make it unreadable by the drive.  Spin the media fast enough and it will fail... violently.  Here is a video showing the warping and failing at the extreme.
The fastest CD/DVD/BD optical drives spin at ~10k RPM at most.
Really high-end magnetic drives spin at 15k RPM, although consumer HDDs (and bulk-storage enterprise HDDs) typically spin at 7200 or 5400 RPM.

A: One aspect that wasn't considered so far is:
They are not just "hard disks", but also "fixed disks".
That means the media (as it cannot be changed) can be extremely clean and of controlled quality, allowing extremely high bit densities through minimum distances between surface and read/write head.
Also CD/DVD/etc. changeable media may be dusty more or less, and they all "wobble" more or less, forcing the laser optics to re-focus.
Some make terrible noises at high RPM, shaking the whole drive (and thus maybe force reduction of RPMs in turn).
Many drives detect vibration and slow down automatically.

A: Hard drives are precision assembled in a clean environment and sealed. They can be (and are) made to very high tolerances.
CD drives are open and designed to accept media that are clean but may have dust and fingerprints on the surface. These cannot be built to the same tolerances as sealed hard drives.
CD drives turn slowly. Hard Drives turn at 7200 rpm (and some expensive drives at 15,000 rpm) in order to provide faster data access and transfer. Tolerances have to be different. The HDD head moves over the platter surface in as little as 3 nanometers. Dust (cannot be introduced except by opening the drive) or stopping the drive rotation while the head was over the drive would damage the platter. Particulate matter can be created in a crash.
They are very different devices used for very different purposes and are not designed to be the same.

A: Don't forget, the CD-ROM was an extension of the audio CD.  The underlying technology was originally designed with music in mind.  It was designed to be fast enough for audio playback, and then later Sony piggybacked the CD-ROM on top of it.  This isn't a format designed with high-speed data transfer as the target use case.

But why do HDDs spin faster

Because rotational speed (and performance in general) is a design priority for hard drives.  Hard drives are precision-manufactured devices.  The spinning platters are almost perfectly uniform in terms of material composition, and are permanently attached to the motor shaft.
Optical drives, on the other hand, were designed for a business case where cost is more important than pure performance.  They're primarily made out of fiberglass because it's cheap, transparent, and lightweight.  An optical disc's density is far from uniform, however.  That means they're not as perfectly balanced as the platter in a hard drive.  When you spin something that's not balanced, it wobbles.  Vibration is an enormous problem in optical drives since the read mechanism involves a laser reflecting off the disc surface; a vibrating disc sends reflections off at an angle, missing the detector and making it more likely that a bit will be misread.  That's a big reason why drive read speeds haven't gotten much faster in decades.  Ever used a portable CD player and jostled it enough that it skipped?  That's what's happening.  DVD and Blu-Ray drives actually spin slower than a lot of CD-ROM drives precisely to  minimize vibration-related problems.
Optical discs are also removable, which means they only attach to the motor's shaft via a friction-fit system.  If the shaft spins too fast or accelerates too quickly, its grip on the disc will slip and the disc and shaft will start grinding on each other.

Why don't they manufacture the arm inside the optical disc
drives to move at the speed of HDDs?

The read heads of these two drives use wildly different mechanical principles.  The read head on a hard drive looks somewhat like a record player. It's a long arm dangling over the spinning platter that can pivot to reach different points along the disc's radius. The arm does not contact the platter, and can whip back and forth through the air relatively quickly thanks to some strong electromagnets.
An optical disk uses a laser mounted on a rail.  A motor pulls a chain that makes the laser module slide back and forth across the rail.  This type of mechanism has significantly more mass and friction than a hard drive's air-suspended read head.  There's no reasonable way to make it move as quickly without damaging something.

Also, can't the head go to a specific part of the spiral track
and read from there?

Absolutely, that's how you can seek to the beginning of a specific song on a CD.

A: In addition to the other answers about why hard disks have better performance than optical disks, another factor (only touched on by @WG481) is that hard disks almost universally have multiple platters that are being accessed at one time, giving parallel read/write opportunities over multiple platter surfaces at the same time.  Where an optical disk only has one read/write opportunity, so all data is forced to be read/written in serial fashion.

A: A Blu-ray laser is rather large, several millimetres, and it's made to fit a slightly unstable optical disc and read it from further away, and the photosensor equipment is also heavy and slow-
cumbersome Ti:sapphire lasers to operate in the labs where they are being developed. To get them out of the laboratory and into consumers' hands, the lasers powering such devices must shrink while maintaining the ability to generate picosecond-long high-energy pulses at high repetition rates.
Also relevent is Density, a DVD platter is 5GB, and a HDD is currently >500GB. That also provides a 100X boost in read/write speed, without adding the higher mechanical speed of the HDD.
The HDD read-head is also smaller, narrower, lower powered and lighter to move across the disk, because it doesn't need a laser and a receiver.


text:
Q: value functions of two maximization problems Let $U,V$ be two real-valued random variable, and let $f:\mathbb R \rightarrow \mathbb R$ be a measurable function. Consider the following two values:
\begin{equation}
V_1=\sup\{\mathbb E((V-f(y(U,V)))(y(U,V)-U))| y:\mathbb R^2\rightarrow \mathbb R \: measurable\} \\
V_2=\mathbb E(\sup_{y\in\mathbb R}(V-f(y))(y-U))
\end{equation}
Clearly, $V_2 \geq V_1$. I am wondering whether they are equal to each other. More specifically, I will assume the problem with value $V_1$ admits a maximizer. What I can show right now is that $V_1=V_2$ provided $f$ is continuous. However, I am not sure whether it is the case if $f$ is only measurable. I would pretty much like to have a positive answer, but a counter-example will be equally appreciated! Thanks!

In general, my problem can be formulated as follows: Let $X$ be a random variable with value in $\mathbb R^2$, and let $G:\mathbb R^2 \times \mathbb R\rightarrow \mathbb R$ be a function which is continuous in the first argument and measurable in the second(i.e., a Caratheodory function). Assume the partial maximization $x\mapsto \sup_yG(x,y)$ is measurable(which is clearly the case if $G(x,y)=(x_1-f(y))(y-x_2)$). I am considering the values given by
\begin{equation}
V_1=\sup\{\mathbb E(G(X,y(X))| y:\mathbb R^2\rightarrow \mathbb R \: measurable\} \\
V_2=\mathbb E(\sup_{y\in\mathbb R}G(X,y))
\end{equation}
I would like to know if these two values are the same or not, assuming problem $V_1$ admits a maximizer.

A: This is a non-answer, focused on the second, or $G(x,y),$ formulation.
My first, naive, reaction is, in the expectation defining $V_2$, there is, for $\epsilon>0$  an $X$-dependent $y_0(X)$ such that for almost all $X$ we have $G(X,y_0(X))>\sup_y G(X,y)-\epsilon.$  Let that function $y_0$ (or a limit as $\epsilon\to0$) be the desired measurable $y$ in the definition of $V_1$.  But, of course, we don't know that $y_0$ is measurable, even though (apparently) the map $\gamma:x\mapsto \sup_y G(x,y)$ is, or else the OP wouldn't be able to take its expectation.
That led to the self-realization that I don't actually know why $\gamma$ is measurable, which is to say, why $V_2$ is well-defined.  Maybe it comes from the assumption that $G$ is a Caratheodory function.  Maybe that argument contains a clue to the OP's problem.
Said differently: for $\epsilon>0$ and almost all $X$ there is a set $S_\epsilon(X)$ such that for all $u\in S_\epsilon(X)$ we have $G(X,u)>\sup_y G(X,y)-\epsilon$, and what is desired is a measurable selection $y_0$ of elements from $S_\epsilon(X),$ one per $X$ value: for almost all $X$ we have $y_0(X)\in S_\epsilon(X).$  A glance at section 6.9, "Measurable choice theorems" in Bogachev's Measure Theory (vol 2, pp. 33-43) shows that this kind of question can be complicated.
So maybe the OP can supply an argument for why his $V_2$ is well-defined, and we can go on from there.


text:
Q: Swift Build Error - No such module 'Feature1' I am getting compile error when I added a framework into my app. Framework Feature1 is built successfully but from module App import is not working.

How to solve this issue?

A: There are several potential misconfigurations the issue can arise for,

*

*Please confirm that you have opened the .xcworkspace but not .xcodeproj file. Also make sure you have build Feature1 first before you build App.

*Make sure that iOS Deployment Target is set same for all modules with App. For example is Apps deployment target is set to 9.0, Feature1s deployment target also need to be set to 9.0.

*Make sure your main module (App) and your used framework (Feature1) have same set of configurations. i.e. If your Project has three configurations, Debug, Release, ReleasePremium than your Framework also need to have three configurations Debug, Release, ReleasePremium. Also make sure that the archive configuration is set same for both App and Feature1. i.e. if your Apps archive scheme is set to ReleasePremium, your Fearure1s archive scheme also need to be set into ReleasePremium.

*Please assure that you do not need to import Feature1 in each .swift files when its already added in the Bridging-Header.h.

*In case of issue came from Pod files, make sure you have uncommented #use_frameworks! into use_frameworks! from you Podfile. Sometime re installing pod works if Feature1 has any dependency on pods.

*If none of the above steps works, delete your derived data folder and try re building.


text:
Q: JQuery Validation plugin: input textbox content validation I'm using the JQuery Validation plugin http://jqueryvalidation.org/ and I have the following scenario:
Example HTML:
   <input type="text" name="glass_name"  id="glass_name">
   <input type="text" name="glass_name_confirm"  id="glass_name_confirm">

Example Javascript:
      $("#form").validate({
        rules: {
            glass_name: {
                required: true
            },
            glass_name_confirm: {
                required: true,
                equalTo: "#glass_name"
            },

How can I validate the input box content against a string words array?. For instance, I don't want that the user in the textbox id=glass_name insert a list of innapropiate words: word1 or word2 or word3, etc.
Thanks in advance!

A: Make a custom rule:
//Add new method:
jQuery.validator.addMethod("validationFilterWords", function(value, element) {
var arrFilter = ["Word1","Word2"];
    return this.optional(element) || ($.inArray(value,arrFilter) === -1);
}, "* Not allowed");

// Add new rule
 rules : {
        glass_name: {
                      validationFilterWords: true,
                      required: true

                     }
    }


text:
Q: Access SQL, Aggregate Sums with multiple WHERE clauses and GROUP BY sales person The following query correctly sums the daily "Sales Total", "Commission" and the "Cost of Goods Sold (COGS)" for each sales person.
The problem is with the "Taxable Sales", "Tax Free Sales", and "Sales Tax" sums because a WHERE clause is needed.  The sub-queries with the WHERE clauses return the sum of all sales people combined for each sales person.
I need to modify the query so it returns an individual value for each sales person.
SELECT Format(DatePart("m",sale_date),"00") & "/" & Format(DatePart("d",sale_date),"00") & "/" & DatePart("yyyy",sale_date) AS [Date],

SALES_REP.rep_Name AS [Sales Person],

Round(Nz(Sum(sales_receipt.SELLING_PRICE*sales_receipt.quantity),0),2)  AS [Sales Total],

Sum((Nz(SALES_RECEIPT.SELLING_PRICE,0)*Nz(SALES_RECEIPT.quantity,0))*(Nz(SALES_RECEIPT.commission_percent,100)*0.001)) AS [Commission],

(SELECT Round(Nz(Sum(sales_receipt.SELLING_PRICE * sales_receipt.quantity),0) ,2)
FROM SALES_RECEIPT
WHERE SALES_RECEIPT.SALE_DATE = Date() and SALES_RECEIPT.SALES_TAX_EXEMPT="No") AS [Taxable Sales],

(SELECT Round(Nz(Sum(sales_receipt.SELLING_PRICE * sales_receipt.quantity),0) ,2)
FROM SALES_RECEIPT
WHERE SALES_RECEIPT.SALE_DATE = Date() and SALES_RECEIPT.SALES_TAX_EXEMPT="Yes") AS [Tax Free Sales],

(SELECT Round(Nz(Sum(sales_receipt.SELLING_PRICE * sales_receipt.quantity),0) ,2) * .05
FROM SALES_RECEIPT
WHERE SALES_RECEIPT.SALE_DATE = Date() and SALES_RECEIPT.SALES_TAX_EXEMPT="No") AS [Sales Tax],

Round(Nz(Sum((Nz(inventory.VENDOR_ACTUAL_PRICE,0))*sales_receipt.quantity),0),2) AS COGS

FROM (SALES_RECEIPT
INNER JOIN SALES_REP ON SALES_RECEIPT.REP_ID = SALES_REP.REP_ID)
LEFT JOIN INVENTORY ON INVENTORY.INVENTORY_ID = SALES_RECEIPT.INVENTORY_ID

WHERE SALES_RECEIPT.SALE_DATE=Date()
GROUP BY Format(DatePart("m",sale_date),"00") & "/" & Format(DatePart("d",sale_date),"00") & "/" & DatePart("yyyy",sale_date), SALES_REP.rep_Name;

The following code is the updated and corrected version based on the answers I received.
SELECT Format(DatePart("m",sale_date),"00") & "/" & Format(DatePart("d",sale_date),"00") & "/" & DatePart("yyyy",sale_date) AS [Date],

SALES_REP.rep_Name AS [Sales Person],

Round(Nz(Sum(sales_receipt.SELLING_PRICE*sales_receipt.quantity),0),2)  AS [Sales Total],

Sum((Nz(SALES_RECEIPT.SELLING_PRICE,0)*Nz(SALES_RECEIPT.quantity,0))*(Nz(SALES_RECEIPT.commission_percent,100)*0.001)) AS [Commission],

tsales.sum_taxable_sales AS [Taxable Sales],

tfsales.sum_tax_free_sales AS [Tax Free Sales],

tsales_tax.sum_sales_tax AS [Sales Tax],

Round(Nz(Sum((Nz(inventory.VENDOR_ACTUAL_PRICE,0))*sales_receipt.quantity),0),2) AS COGS

FROM ((((SALES_RECEIPT
INNER JOIN SALES_REP ON SALES_RECEIPT.REP_ID = SALES_REP.REP_ID)
LEFT JOIN INVENTORY ON INVENTORY.INVENTORY_ID = SALES_RECEIPT.INVENTORY_ID)

LEFT JOIN

(SELECT SALES_RECEIPT.rep_ID, Round(Nz(Sum(sales_receipt.SELLING_PRICE * sales_receipt.quantity),0) ,2) as sum_taxable_sales

FROM SALES_RECEIPT
WHERE SALES_RECEIPT.SALE_DATE = Date() and SALES_RECEIPT.SALES_TAX_EXEMPT="No"
GROUP BY SALES_RECEIPT.rep_ID)
tsales ON tsales.rep_ID = SALES_REP.rep_ID)

LEFT JOIN

(SELECT SALES_RECEIPT.rep_ID, Round(Nz(Sum(sales_receipt.SELLING_PRICE * sales_receipt.quantity),0) ,2) as sum_tax_free_sales
FROM SALES_RECEIPT
WHERE SALES_RECEIPT.SALE_DATE = Date() and SALES_RECEIPT.SALES_TAX_EXEMPT="Yes"
GROUP BY SALES_RECEIPT.rep_ID) tfsales
 ON tfsales.rep_ID = SALES_REP.rep_ID)

LEFT JOIN

(SELECT SALES_RECEIPT.rep_ID, Round(Nz(Sum(sales_receipt.SELLING_PRICE * sales_receipt.quantity),0) ,2)* .05 as sum_sales_tax

FROM SALES_RECEIPT
WHERE SALES_RECEIPT.SALE_DATE = Date() and SALES_RECEIPT.SALES_TAX_EXEMPT="No"
GROUP BY SALES_RECEIPT.rep_ID)
tsales_tax ON tsales_tax.rep_ID = SALES_REP.rep_ID

WHERE SALES_RECEIPT.SALE_DATE=Date()

GROUP BY Format(DatePart("m",sale_date),"00") & "/" & Format(DatePart("d",sale_date),"00") & "/" & DatePart("yyyy",sale_date)
, SALES_REP.rep_Name
, tsales.sum_taxable_sales
, tfsales.sum_tax_free_sales
, tsales_tax.sum_sales_tax
;

A: You can use a sub-query to properly group the records, and join on the sales person. I am making an assumption in the query that rep_name is the key, otherwise replace this in the JOIN ON.
SELECT Format(DatePart("m",sale_date),"00") & "/" & Format(DatePart("d",sale_date),"00") & "/" & DatePart("yyyy",sale_date) AS [Date],

SALES_REP.rep_Name AS [Sales Person],

Round(Nz(Sum(sales_receipt.SELLING_PRICE*sales_receipt.quantity),0),2)  AS [Sales Total],

Sum((Nz(SALES_RECEIPT.SELLING_PRICE,0)*Nz(SALES_RECEIPT.quantity,0))*(Nz(SALES_RECEIPT.commission_percent,100)*0.001)) AS [Commission],

tsales.sum_taxable_sales AS [Taxable Sales],

Round(Nz(Sum((Nz(inventory.VENDOR_ACTUAL_PRICE,0))*sales_receipt.quantity),0),2) AS COGS

FROM ((SALES_RECEIPT
INNER JOIN SALES_REP ON SALES_RECEIPT.REP_ID = SALES_REP.REP_ID)
LEFT JOIN INVENTORY ON INVENTORY.INVENTORY_ID = SALES_RECEIPT.INVENTORY_ID)

LEFT JOIN (SELECT SALES_RECEIPT.rep_ID, Round(Nz(Sum(sales_receipt.SELLING_PRICE * sales_receipt.quantity),0) ,2) as sum_taxable_sales

FROM SALES_RECEIPT
WHERE SALES_RECEIPT.SALE_DATE = Date() and SALES_RECEIPT.SALES_TAX_EXEMPT="No"
GROUP BY SALES_RECEIPT.rep_ID) tsales ON tsales.rep_ID = SALES_REP.rep_ID

WHERE SALES_RECEIPT.SALE_DATE=Date()

GROUP BY Format(DatePart("m",sale_date),"00") & "/" & Format(DatePart("d",sale_date),"00") & "/" & DatePart("yyyy",sale_date), SALES_REP.rep_Name;

Simplified syntax would be:
SELECT a.id, b.value
FROM a
JOIN (SELECT b.id, SUM(b.value) as value FROM b) b ON a.id = b.id


text:
Q: Set Window owner inside of an UserControl in WPF I have an UserControl that shows a window without an icon in the Taskbar, the problem is when the main window lost the focus and get it again the window without taskbar icon is behind the main window and is difficult show it in front again, this issue is solved using window.Owner = this; when the class is a window, but when is UserControl or other type (e.g. ListBoxItem, Viewbox) I can't do this. I tried to do this control.Owner = (Window)this; but the result throws an exception that a Grid cannot be converted into a Window

A: use
window.Owner = Window.GetWindow(this);

A:  for (int  index=0;index< App.Current.Windows.Count;index++ )
        {
            if (App.Current.Windows[index].Title == "MyWindow")
                control.Owner = App.Current.Windows[index];
        }

here Title is the Title of Window which you want to set as owner.


text:
Q: How to get the content of "Google Dictionary" by python script Thank to the script, I've logged in google successfully.
But I replaced the value of "gv_home_page_url" with http:// www.google.com.tw/dictionary/wordlist?hl=zh-TW, the error occured.
The message is "
urllib2.HTTPError: HTTP Error 500: Internal Server Error"
Any idea will be appreciated, thanks.

A: That's not a valid URL. If you try to enter it in your bar, you'll get redirected to Google search results. Using urllib2, you'll get an error.
See here for another way to get data from Google Dictionary:
http://googlesystem.blogspot.com/2009/12/on-googles-unofficial-dictionary-api.html

A: Does Google require an SSL url? You're using "http://" but the example script uses "https://"


text:
Q: Apache redirect seems to ignore ServerName I have a couple virtual host files. The first one redirects all traffic for http://www.mysite.com to the https version:
<VirtualHost *:80>
   ServerName www.mysite.com
   Redirect permanent / https://www.mysite.com/
</VirtualHost>

<VirtualHost *:443>
   ServerName www.mysite.com
   # additional configuration
</VirtualHost>

The second defines a VirtualDocumentRoot so that sites in directories such as /var/www/www.othersite.com will be served.
<VirtualHost *:80>
    ServerAdmin webmaster@localhost
    VirtualDocumentRoot /var/www/%0
    VirtualScriptAlias  /var/www/%0/cgi-bin/
</VirtualHost>

I also have NameVirtualHost definitions in the ports.conf file (in case that is helpful):
NameVirtualHost *:443
NameVirtualHost *:80

The problem is that all traffic seems to be redirected to https://www.mysite.com. I would expect that the ServerName www.mysite.com line in the first virtual host file would only match www.mysite.com so that visiting http://www.othersite.com would serve content from /var/www/www.othersite.com. When I comment out the entire port 80 VirtualHost definition from the first file, http://www.othersite.com loads as expected. Am I missing something here? How do I only redirect http to https for www.mysite.com?
Edit:
The reason I can't put the ServerName as http://www.othersite.com in the second VirtualHost definition is that there are multiple sites in /var/www that also need to be served.

A: Have you tried to add ServerName www.othersite.com directive to the second virtual host?

A: After some digging, I found this answer, which led me to add the following to my second VirtualHost definition:
ServerName host
ServerAlias *

A couple other answers that were very helpful:

*

*https://stackoverflow.com/a/550581

*https://serverfault.com/a/463879/221978