lundi 31 août 2015

intellij internal webserver using htaccess

IntelliJ 14 has a built-in Webserver where you can run html-files on localhost port 63342. Is there any possibility to use rewrite rules (like modrewrite) within a .htaccess file or something similar?

Or do I have to install a local webserver for this?

Regards, Jens



via Chebli Mohamed

When using a RegEx in AutoFixture ISpecimenBuilder, Why do I always get back the same value?

My builder is set up to either deal with a Parameter or a Property. This may change in the future, but for now this is what I have in my builder:

public class UserNameBuilder : ISpecimenBuilder
{
    public object Create(object request, ISpecimenContext context)
    {
       var propertyInfo = request as PropertyInfo;
        if (propertyInfo != null && propertyInfo.Name == "UserName" && propertyInfo.PropertyType == typeof(string))
        {
            return GetUserName();
        }

        var parameterInfo = request as ParameterInfo;
        if (parameterInfo != null && parameterInfo.Name == "userName" && parameterInfo.ParameterType == typeof(string))
        {
            return GetUserName();
        }

        return new NoSpecimen(request);
    }

    static object GetUserName()
    {
        var fixture = new Fixture();
        return new SpecimenContext(fixture).Resolve(new RegularExpressionRequest(@"^[a-zA-Z0-9_.]{6,30}$"));
    }
}

My UserName object is a ValueType object and is as follows:

public class UserName : SemanticType<string>
{
    private static readonly Regex ValidPattern = new Regex(@"^[a-zA-Z0-9_.]{6,30}$");

    public UserName(string userName) : base(IsValid, userName)
    {
        Guard.NotNull(() => userName, userName);
        Guard.IsValid(() => userName, userName, IsValid, "Invalid username");
    }

    public static bool IsValid(string candidate)
    {
        return ValidPattern.IsMatch(candidate);
    }

    public static bool TryParse(string candidate, out UserName userName)
    {
        userName = null;

        try
        {
            userName = new UserName(candidate);
            return true;
        }
        catch (ArgumentException ex)
        {
            return false;
        }
    }
}

The UserName class inherits from SemanticType which is a project that provides a base for my value types.

Whenever I use AutoFixture as follows:

var fixture = new Fixture();
fixture.Customizations.Add(new UserNameBuilder());

var userName = fixture.Create<UserName>();

I always get the value "......" I thought I would get a different value each time. Is what I'm seeing expected behavior?

Thanks



via Chebli Mohamed

swift remoteControlReceivedWithEvent giving fatal error: unexpectedly found nil while unwrapping an Optional value

I am using below function to play/pause the music and I am implementing remote controls:

in ViewController.swift :

static let sharedInstance = ViewController()
@IBOutlet var PausePlay: UIButton!


var BackgroundAudio = AVAudioPlayer(contentsOfURL: NSURL(fileURLWithPath: NSBundle.mainBundle().pathForResource("Ants", ofType: "mp3")!), error: nil)

//in info.playlist I have added 'Required background modes and add to idem 0 ap plays audio airplay then below code to play even when iphone is locked: -marcin

    PausePlay.setTitle("Play", forState: UIControlState.Normal)

    AVAudioSession.sharedInstance().setCategory(AVAudioSessionCategoryPlayback, error: nil)

    // Do any additional setup after loading the view, typically from a nib.
    PausePlay.setTitle("Play", forState: UIControlState.Normal)
    if NSClassFromString("MPNowPlayingInfoCenter") != nil {
        let image:UIImage = UIImage(named: "logo_player_background")!
        let albumArt = MPMediaItemArtwork(image: image)
        var songInfo: NSMutableDictionary = [
            MPMediaItemPropertyTitle: "Ants",
            MPMediaItemPropertyArtist: "The App",
            MPMediaItemPropertyArtwork: albumArt
        ]
        MPNowPlayingInfoCenter.defaultCenter().nowPlayingInfo = songInfo as [NSObject : AnyObject]
    }
    if (AVAudioSession.sharedInstance().setCategory(AVAudioSessionCategoryPlayback, error: nil)) {
        println("Receiving remote control events")
        UIApplication.sharedApplication().beginReceivingRemoteControlEvents()
    } else {
        println("Audio Session error.")
    }

in AppDelegate.swift I have this for remote control:

override func remoteControlReceivedWithEvent(event: UIEvent) {
        if event.type == UIEventType.RemoteControl {
        if event.subtype == UIEventSubtype.RemoteControlPlay {
            println("received remote play")
            ViewController.sharedInstance.FuncPausePlay() // these are producing terrible error
        } else if event.subtype == UIEventSubtype.RemoteControlPause {
            println("received remote pause")
            ViewController.sharedInstance.FuncPausePlay() // these are producing terrible error
        } else if event.subtype == UIEventSubtype.RemoteControlTogglePlayPause {
            println("received toggle")
            ViewController.sharedInstance.BackgroundAudio.stop()
        }
    }
}

when I am hitting play button then app works file on my phone (it plays the sound) but I am getting below info in Xcode error window:

Receiving remote control events 2015-08-31 19:33:42.735 The App[1501:292732] Unable to simultaneously satisfy constraints. Probably at least one of the constraints in the following list is one you don't want. Try this: (1) look at each constraint and try to figure out which you don't expect; (2) find the code that added the unwanted constraint or constraints and fix it. (Note: If you're seeing NSAutoresizingMaskLayoutConstraints that you don't understand, refer to the documentation for the UIView property translatesAutoresizingMaskIntoConstraints) ( "", "", "", "", "", "" ) Will attempt to recover by breaking constraint Make a symbolic breakpoint at UIViewAlertForUnsatisfiableConstraints to catch this in the debugger. The methods in the UIConstraintBasedLayoutDebugging category on UIView listed in may also be helpful.

then when I lock my phone, sound is still playing (which if great) but when I am hitting pause button on remote control screen (when my phone is locked) then app is freezing / stopping and I get below info in Xcode :

received remote pause fatal error: unexpectedly found nil while unwrapping an Optional value (lldb)

What am I doing wrong? Please help.



via Chebli Mohamed

How can I visualize a data.frame with a values column and a label column in R?

I'm using the pdf command and ggplot2 to create couple different types of graphs and while I'm at it I'd like to throw in some simple tables (with, for example, column labels being coefficient names and rows having values) but I'm not sure to make a "plot" out of that without going separately into excel to make a table (but then I don't know how to insert it into the pdf I generate with R)

For example suppose I've got a data.frame like this one:

set.seed(1)
foo = data.frame(val1=rnorm(5), val2=rnorm(5), columnLabels=c('A','B','C','D','F'))

Is there a simple way to "plot" a simple table with those column labels, with row labels like c('Val 1', 'Val2') and with the corresponding values?



via Chebli Mohamed

Email Attachment From Lotusscript Agent

I have documents that get processed via a scheduled LotusScript agent. Each document has a $FILE field which is a jpg photo. In my agent, I want to take that photo on the document and email it to a specified address. Is this possible with a scheduled LotusScript agent?



via Chebli Mohamed

NetLogo: how to make the calculation of turtle movement easier?

I am working with NetLogo code written with somebody else (freely available to public). I try to understand how the procedure of turtle moving is elaborated and, most important - how make it computationally faster without loosing sensitivity of turtle movement in relation to worlds' patches?

I suppose that the most of the calculation time is used to calculate the distance of each step of turtle movement - I would like to measure only one variable from patch of turtle's origins to last patch where it will stay. I have decoded some of features but I am still not able to reproduce them. I'll really appreciate any help !

My understanding what the procedure could accomplish:

enter image description here

to move-turtles                                                                    
   ifelse perceptdist = 0                                                           
    [ifelse patch-ahead 1 != nobody 
     [rt random moveangle lt random moveangle                                      
      let xcorhere [pxcor] of patch-here                                           
      let ycorhere [pycor] of patch-here                                           
      fd 1
      let xcornext [pxcor] of patch-here                                           
      let ycornext [pycor] of patch-here                                           
      set dist sqrt (xcor * xcor + ycor * ycor)                                        
      set t_dispers (t_dispers + 1)                                                 
      set energy (energy - (1 / efficiency))                                       
      let flightdistnow sqrt ((xcornext  - xcorhere) * (xcornext  - xcorhere) + (ycornext - ycorhere) * (ycornext - ycorhere))   
      set flightdist (flightdist + flightdistnow)

    ][]]     

   [let np patches in-radius perceptdist          ; find the patch with the highest totalattract value within perception range                                 
    let bnp max-one-of np [totalattract]                                              
    let ah [totalattract] of patch-here
    let xcorhere [pxcor] of patch-here
    let ycorhere [pycor] of patch-here                                             
    let abnp [totalattract] of bnp                                                 
    ifelse abnp - ah > 2 and random-float 1 < 0.1                                  
     [move-to bnp                                     ; move to the patch with the highest attractivity value
      let xbnp [pxcor] of bnp                                 
      let ybnp [pycor] of bnp
      let flightdistnow sqrt ((xbnp - xcorhere) * (xbnp - xcorhere) + (ybnp - ycorhere) * (ybnp - ycorhere)) 
      set t_dispers (t_dispers + flightdistnow)                
      set energy (energy - (flightdistnow / efficiency))      ; how the turtle decision to stay/move further is made - ratio of turtle energy/efficiency  
      set flightdist (flightdist + flightdistnow)
      set dist sqrt (xcor * xcor + ycor * ycor)               

   [rt random moveangle lt random moveangle                                        
    set dist sqrt (xcor * xcor + ycor * ycor)                                      
    set t_dispers (t_dispers + 1)                                                  
    set energy (energy - (1 / efficiency))                                         
    let xcorhere2 [pxcor] of patch-here                                           
    let ycorhere2 [pycor] of patch-here                                            
    fd 1
    let xcornext2 [pxcor] of patch-here                                            
    let ycornext2[pycor] of patch-here                                             
    set dist sqrt (xcor * xcor + ycor * ycor)                                         
    let flightdistnow sqrt ((xcornext2  - xcorhere2) * (xcornext2  - xcorhere2) + (ycornext2 - ycorhere2) * (ycornext2 - ycorhere2))   
    set flightdist (flightdist + flightdistnow)

end  



via Chebli Mohamed

How to prevent loading the same data over and over in angularJS

I have an object that contains some data that I need to load when my application starts. Once its loaded I need to be able to reuse in multiple places on my application.

What is the best way to do this?

Right now I have a factory that I inject into my controller and I pull the data, the problem is that I'm doing the data pull multiple times.

What would be the best way to pull the data only when I load the application? I would only need to access the data on my templates and pull the correct Key Value from the object where I need.



via Chebli Mohamed