Skip to content

Instantly share code, notes, and snippets.

View rominirani's full-sized avatar

Romin Irani rominirani

  • Mumbai
View GitHub Profile
@rominirani
rominirani / gocourse - Week 2 Exercise solutions
Created June 30, 2015 12:02
Week 2 Exercise Solutions from Go Course (http://gocourse.slack.com)
Exercise 11 : Line #5 and Line #6 have errors since you cannot have a pointer to a constant value.
Exercise 12 : The pointer is not initialized to anything (nil). As a result,any operation on this is going to be problematic (Null Pointer Exception). On running the program, it shows panic: runtime error: invalid memory address or nil pointer dereference.
Exercise 13 : a() is invoked first and this prints the value of the global variable i (10), which was initialized to 10 at the start of the program. The next function invoked is b() and this initializes a local variable i to 20. Hence the output is 20. This is a local variable within the scope of the function and does not affect the global variable i, which still has the value of 10. Hence the last function a() invocation simply prints the value of the global variable i that is still 10.
Exercise 14 : main() creates a localized variable i and hence the first output is 20. Then b() is invoked, which also creates a localized variable i, whose value is 40. An
@rominirani
rominirani / gocourse - Week 1 Exercise Solutions
Created June 28, 2015 08:56
Week 1 Exercise Solutions from Go Course (http://gocourse.slack.com)
Week 1 Exercises from Go Course (http://gocourse.slack.com).
Exercise 1 :
/tmp/sandbox760491916/main.go:6: syntax error: unexpected semicolon or newline before {
Needed to push the start parenthesis to the line contain main(). After that it gave the obvious errors i.e.
- package "os" is imported but not used
- println - cannot refer to unexported name fmt.println
package com.mindstorm.famousquotesandroid;
import android.accounts.AccountManager;
import android.app.Activity;
import android.app.ProgressDialog;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.AsyncTask;
import android.os.Bundle;
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.USE_CREDENTIALS" />
<!DOCTYPE html>
<html>
<head>
<title>Famous Quotes</title>
</head>
<body>
<div id="login">
<input id="loginButton" type="button" value="Login"/>
</div>
@ApiMethod(name = "insertQuote", scopes = {Constants.EMAIL_SCOPE},
clientIds = {Constants.WEB_CLIENT_ID,
Constants.ANDROID_CLIENT_ID,
com.google.api.server.spi.Constant.API_EXPLORER_CLIENT_ID},
audiences = {Constants.ANDROID_AUDIENCE})
public Quote insertQuote(Quote quote, User user) throws UnauthorizedException {
if (user == null) throw new UnauthorizedException("User is Not Valid");
PersistenceManager mgr = getPersistenceManager();
package com.mindstorm.famousquotes.entity;
public class Constants {
public static final String WEB_CLIENT_ID = "756161739003-0l5c7ptti2j42l28j5anijr5mukks835.apps.googleusercontent.com";
public static final String ANDROID_CLIENT_ID = "756161739003-9e1gefoeo2f9tsnrbjchtsn2shfq7q8k.apps.googleusercontent.com";
public static final String ANDROID_AUDIENCE = WEB_CLIENT_ID;
public static final String EMAIL_SCOPE = "https://www.googleapis.com/auth/userinfo.email";
}
<!DOCTYPE html>
<html>
<head>
<title>Famous Quotes</title>
</head>
<body>
<form action="javascript:void(0);">
<h2>List Quotes</h2>
<div><input id="listQuote" type="submit" value="List Quotes"></div>
<!DOCTYPE html>
<html>
<head>
<title>Famous Quotes</title>
</head>
<body>
<form action="javascript:void(0);">
<h2>List Greetings</h2>
<div><input id="listGreeting" type="submit" value="Submit"></div>
package com.mindstorm.famousquotesandroid;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import com.google.api.client.extensions.android.http.AndroidHttp;
import com.google.api.client.json.gson.GsonFactory;