This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
input = '1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0'; %輸入32-bit二進位整數 | |
x = str2num(input); %將輸入轉成向量 | |
n = length(x); | |
y = [0, 2 .^ (n-2:-1:0)]; %2的整數冪 | |
if ~x(1) %如果是正數 | |
result = dot(x,y); %各位元與2的整數冪內積即為十進位 | |
else %如果是負數 | |
x = ~x; %取補數 | |
result = -dot(x,y)-1; %內積後取負減一 | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
GraphManager.instance.getMe { completion: | |
(user: MSGraphUser?, error: Error?) in | |
DispatchQueue.main.async { | |
guard let currentUser = user, error == nil else { | |
// Failed to get user | |
print("Error getting user: \(String(describing: error))") | |
return | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public func getMe(completion: @escaping(MSGraphUser?, Error?) -> Void) { | |
let meRequest = NSMutableURLRequest(url: URL(string: "\(MSGraphBaseURL)/me")!) | |
let meDataTask = MSURLSessionDataTask(request: meRequest, client: self.client, completion: { | |
(data: Data?, response: URLResponse?, graphError: Error?) in | |
guard let meData = data, graphError == nil else { | |
completion(nil, graphError) | |
return | |
} | |
do { | |
// Deserialize response as a user |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import MSAL | |
func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey : Any] = [:]) -> Bool { | |
guard let sourceApplication = options[UIApplication.OpenURLOptionsKey.sourceApplication] as? String else { | |
return false | |
} | |
return MSALPublicClientApplication.handleMSALResponse(url, sourceApplication: sourceApplication) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<key>CFBundleURLTypes</key> | |
<array> | |
<dict> | |
<key>CFBundleURLSchemes</key> | |
<array> | |
<string>msauth.$(PRODUCT_BUNDLE_IDENTIFIER)</string> | |
</array> | |
</dict> | |
</array> | |
<key>LSApplicationQueriesSchemes</key> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
AuthenticationManager.instance.getTokenSilently { | |
(token: String?, error: Error?) in | |
DispatchQueue.main.async { | |
guard let _ = token, error == nil else { | |
// If there is no token or if there's an error, | |
// no user is signed in, so stay here | |
return | |
} | |
// Since we got a token, a user is signed in | |
// Go to welcome page |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
AuthenticationManager.instance.getTokenInteractively(parentView: self) { | |
(token: String?, error: Error?) in | |
DispatchQueue.main.async { | |
guard let _ = token, error == nil else { | |
// Show the error and stay on the sign-in page | |
let alert = UIAlertController(title: "Error signing in", | |
message: error.debugDescription, | |
preferredStyle: .alert) | |
alert.addAction(UIAlertAction(title: "OK", style: .default, handler: nil)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function B=M_det(A) %Handwrited n*n matrix determinant function | |
[n,n1]=size(A); | |
if n~=n1 | |
fprintf('Error using det\nMatrix must be square.\n') | |
elseif n==1 | |
B=A; | |
elseif n==2 | |
B=det2(A); | |
else | |
B=det3(A); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function obj = varassign( obj, var ) | |
if nargin < 2 || isempty(var) | |
return | |
end | |
nvarin = numel(var); | |
assert( ~mod( nvarin, 2 ), 'Field and value input arguments must come in pairs.' ); | |
for i = 1:2:nvarin-1 | |
mc = metaclass(obj); | |
[~, LocB] = ismember(lower(var{i}),lower({mc.PropertyList.Name})); | |
obj.(mc.PropertyList(LocB).Name) = var{i+1}; |