Alamofire request keeps coming nil - swift2

So I am testing my code to see if i get connection with my php service, but I am still getting nil with this simple code:
<?php
$arr = array('a' => 1, 'b' => 2, 'c' => 3, 'd' => 4, 'e' => 5);
echo json_encode($arr);
?>
The php output is: {"a":1,"b":2,"c":3,"d":4,"e":5}
but when I try it in the app, xcode console shows nil as result.
My alamofire request is:
Alamofire.request(.GET,url).responseJSON{ _,_, result in
print(result.value)
}
I had to override Info.plist because the server I am using is http instead of https with the following:
<key>NSAppTransportSecurity</key>
<dict>
<key>NSExceptionDomains</key>
<dict>
<key>primefitness.hostoi.com</key>
<dict>
<key>NSExceptionAllowsInsecureHTTPLoads</key>
<true/>
<key>NSExceptionMinimumTLSVersion</key>
<string>TLSv1.1</string>
<key>NSIncludesSubdomains</key>
<true/>
</dict>
</dict>
I am new to swift, and I got no idea on how to debug or track the request. Any suggestions?
EDIT:
I changed "mysite" to the actual site, to avoid confusions

The answer was simple, the hosting im using, uses an analitics javascript that was putting garbage to the end of my json, as stated by Ashish Kakkad, so i just disabled it.

Related

how to retrieve user setting in iOS? [Xcode 7 + Swift 2]

I am using Xcode 7 + Swift 2.
I added a setting.bundle to the root of my app with a single text field.
Root.plist looks like this:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>StringsTable</key>
<string>Root</string>
<key>PreferenceSpecifiers</key>
<array>
<dict>
<key>Type</key>
<string>PSGroupSpecifier</string>
<key>Title</key>
<string>Controller Settings:</string>
</dict>
<dict>
<key>Type</key>
<string>PSTextFieldSpecifier</string>
<key>Title</key>
<string>Enter Text</string>
<key>Key</key>
<string>key</string>
<key>DefaultValue</key>
<string>Text</string>
<key>IsSecure</key>
<false/>
<key>KeyboardType</key>
<string>NumbersAndPunctuation</string>
<key>AutocapitalizationType</key>
<string>None</string>
<key>AutocorrectionType</key>
<string>No</string>
</dict>
</array>
</dict>
</plist>
I then try to:
Read the default value ("Text")
Change the text field in the iOS settings and then read the new String.
I used this two lines of code:
let settings = NSUserDefaults.standardUserDefaults()
let setting_value = settings.stringForKey("key")! as String
but all i get is this error and the app would not continue:
fatal error: unexpectedly found nil while unwrapping an Optional value
all I want is to read the setting and display the String to a label.
Thanks.
EDIT:
I Understand now that the error is because the value in not assigned yet.
to prevent the error I put 'if' before:
if let name = settings.stringForKey("key") {
print(name)
}
but how can I actually read the value inside "key"?

Can't use RubyPress gem gives getaddrinfo: No such host is known. (SocketError)

I am trying to use a gem called RubyPress which allows to use Wordpress' xml-rpc api from ruby. But it always gives me this error:
getaddrinfo: No such host is known. (SocketError)
Here's my code:
require 'rubypress'
wp = Rubypress::Client.new(:host => "localhost/wordpress",
:username => "admin",
:password => "admin")
p wp.getOptions
I am able to connect fine using another gem called wp_rpc but rubypress doesn't seem to work. Rubypress seems to be maintained so i want to use it, it also seems to have more features.
Also, even when i try connecting to a real site, it gives a 403 error which is very strange.
I am running the server using XAMPP on Windows 7. How can I get it to work?
UPDATE:
Here's the code i used for posting, now it doesn't seem to post. Not sure where i went wrong.
wp.newPost( :blog_id => 0, # 0 unless using WP Multi-Site, then use the blog id
:content => {
:post_status => "publish",
:post_date => Time.now,
:post_content => "This is the body",
:post_title => "RubyPress is the best!",
:post_name => "/rubypress-is-the-best",
:post_author => 1, # 1 if there is only the admin user, otherwise the user's id
:terms_names => {
:category => ['Category One','Category Two','Category Three'],
:post_tag => ['Tag One','Tag Two', 'Tag Three']
}
}
)
Note: This is from the rubypress github page. Those categories and tags are not present on the blog, is that the reason?
host must be a host name (e.g. "localhost" in this particular case, or, say, "google.com"):
require 'rubypress'
wp = Rubypress::Client.new(host: "localhost",
username: "admin",
password: "admin",
path: "/wordpress/xmlrpc.php")
Probably, you might need to tune the path parameter up to point exactly to where WP’s RPC endpoint is to be found.

Match everythin between tag as comment

I would like to highlight every thing between
!&
some explanation
&!
As a comment.
I know comment are match with
- name: comment.line.exclamation-mark.fortran
match: (?i)\!.*$
in my fortran.YAML-tmLanguage.
But I don't see how to extend this to the case above.
Since the comments are multiline, you need to split the regex into two expressions, one called begin and one called end.
This allows you to parse multiple lines.
I dont really use YAML, but this code from the C tmLanguage should get you started (Comment style is /* COMMENT */):
<dict>
<key>begin</key> <string>\s*/\*</string>
<key>captures</key>
<dict>
<key>0</key> <dict> <key>name</key>
<string>punctuation.definition.comment.c</string> </dict>
</dict>
<key>end</key> <string>\*/</string>
<key>name</key> <string>comment.block.c</string>
</dict>
So you could use \s\!\& for the begin-tag and \&\! for the end-tag.
I found the below work. Thanks #LinuCC.
# order matter: this block comment syntax should be before the line comment syntax
- name: comment.block.fortran
begin: (?i)\!&
end: (?i)&\!
captures:
'0': {name: comment.line.exclamation-mark.fortran}
- name: comment.line.exclamation-mark.fortran
match: (?i)\!.*$
To make comment toggling work you also need, in another file,
# [PackageDev] target_format: plist, ext: tmPreferences
---
name: Comments
uuid: 40e092f2-ee49-4cbd-8afb-4a5c4f581463
scope: source.fortran
settings:
shellVariables:
- name: TM_COMMENT_START
value: '! '
- name: TM_COMMENT_START_2
value: '!&'
- name: TM_COMMENT_END_2
value: '&!'

Shibboleth authentication in Rails

I am having a struggle getting this to work so I've created a hell-world Rails app to try and get this to work.
Here's the repo with the code that is not working: https://github.com/pitosalas/shibtry
Here's what I've done starting from an empty Rails application:
I've added two gems to gem files:
gem 'omniauth-shibboleth'
gem 'rack-saml'
I got the shibboleth meta data from my university's web site and converted it using shib_conv.rb into the corresponding YAML: ./config.yml
I've updated routes adding get '/auth/:provider/callback', to: 'sessions#create'
I've put a breakpoint at SessionController#create
I've added initializers: omniauth.rb:
Rails.application.config.middleware.use OmniAuth::Builder do
provider :shibboleth, {
:shib_session_id_field => "Shib-Session-ID",
:shib_application_id_field => "Shib-Application-ID",
:debug => true,
:extra_fields => [
:"unscoped-affiliation",
:entitlement
]
}
end
I've added rack_sam.rb initializer:
Rails.application.config.middleware.insert_after Rack::ETag, Rack::Saml,
{ :metadata => "#{Rails.root}/config/metadata.yml"}
Now, run the server and go to http://0.0.0.0:3000/auth/shibboleth and I get an error:
undefined method `[]' for nil:NilClass'
which is traced back to this line in rack-saml/misc/onelogin_setting.rb line 13 which is:
settings.idp_sso_target_url = #metadata['saml2_http_redirect']
in other words, looking for the metadata hash for that key. It happens that in my metadata.yml file that key is present, but by the time I get to this onelogin_setting.rb line 13, #metadata is nil (it should contain the contents of the file) and consequently that key doesn't exist.
And that's where, for now, the trail dries up.
I bypassed Shibboleth totally. My goal was to allow login to my universities authentication system specifically to allow students to log in with their student login, which is fronted by google apps. So this was much easier: https://developers.google.com/identity/sign-in/web/
Looks like you forgot to add your config file to the initializer:
Rails.application.config.middleware.insert_after Rack::ETag, Rack::Saml,
{
:metadata => "#{Rails.root}/config/metadata.yml",
:config => "#{Rails.root}/config/rack-saml.yml"
}
And the saml_idp setting in the rack-saml.yml must match the key for the idp_lists entry in your metadata.yml

Mac OSX 10.9.2, launchd error: "launchctl: Dubious ownership on file (skipping)"

I'm getting the same error launchctl: Dubious ownership on file (skipping): ~.plist
nothing found to load from running a launchctl load command in three different locations as follows, and none of them is working:
sudo launchctl load /Library/LaunchDaemons/updates.novel.plist
sudo launchctl load /Library/LaunchAgents/updates.novel.plist
sudo launchctl load /Users/username/Library/LaunchAgents/updates.novel.plist
Below is my updates.novel.plist file, could you please take a look and let me know what is the problem? thanks
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>GroupName</key>
<string>admin</string>
<key>UserName</key>
<string>Username</string>
<key>Debug</key>
<true/>
<key>Label</key>
<string>updates.novel</string>
<key>ProgramArguments</key>
<array>
<string>/Applications/AMPPS/php-5.3/bin/php</string>
<string>/Applications/AMPPS/www/files/allnovels/novel.php</string>
<string>--daemon</string>
</array>
<key>StandardErrorPath</key>
<string>/var/log/files/error.1.log</string>
<key>StandardOutPath</key>
<string>/var/log/files/error.2.log</string>
<key>RunAtLoad</key>
<true/>
<key>AbandonProcessGroup</key>
<true/>
<key>StartCalendarInterval</key>
<dict>
<key>Hour</key>
<integer>14</integer>
<key>Minute</key>
<integer>0</integer>
</dict>
</dict>
</plist>
launchd services need to be started by the user who owns the plist file. If the owner is not root, then the service must not be launched with sudo.
Also, the permissions on the file must deny write access to all users except the owner.
Finally, the file must be a regular file (ie not a pipe or a socket or anything else).
In man launchctl we can read:
Note that per-user configuration files (LaunchAgents) must be owned by the user loading them. All sytem-wide daemons (LaunchDaemons) must be owned by root. Configuration files must not be group- or world-writable. These restrictions are in place for security reasons.
This is how launchctl.c checks that:
bool path_goodness_check(const char *path, bool forceload) {
if (forceload) {
return true;
}
if (sb.st_mode & (S_IWOTH|S_IWGRP)) {
fprintf(stderr, "%s: Dubious permissions on file (skipping): %s\n", getprogname(), path);
return false;
}
if (sb.st_uid != 0 && sb.st_uid != getuid()) {
fprintf(stderr, "%s: Dubious ownership on file (skipping): %s\n", getprogname(), path);
return false;
}
if (!(S_ISREG(sb.st_mode) || S_ISDIR(sb.st_mode))) {
fprintf(stderr, "%s: Dubious path. Not a regular file or directory (skipping): %s\n", getprogname(), path);
return false;
}
if ((!S_ISDIR(sb.st_mode)) && (fnmatch("*.plist", path, FNM_CASEFOLD) == FNM_NOMATCH)) {
fprintf(stderr, "%s: Dubious file. Not of type .plist (skipping): %s\n", getprogname(), path);
return false;
}
return true;
}
So in other words, correct the ownership, permissions or path of your .plist file or force the loading (-F).

Resources