Posts

Showing posts from May, 2011

Using GWT as a RESTful frontend for a RESTful Go backend

Basically it  doesn't work without hacks.. . The problem ist that the XMLHttpRequest cannot post or retrieve data to or from a location that isn't identical to the host where the application is running. So you can't run a GWT dev server on  localhost:8888   and communicate with Go's backend which must run on a distinct port of you dev machine (e.g.  localhost:8080 ). Of course you can compile your GWT frontend that communicates with the Go backend via REST and run it within the Go server environment. But this dev practice isn't exactly what's called "rapid" or even feasible at all.   In the case you want try it anyway: GWT's wrapper for  XMLHttpRequest  is the  RequestBuilder  class which is encouraged to be used instead of the raw XMLHttpRequest class which is available in GWT as well. You can find a  nice explanation of how to use GWT as RESTful frontend  in GWT's docs.   After all I will not give up my architectural approach to build a  RE

Git: Undo a merge solution

# you are on the  dev  branch git checkout master git merge dev  # here you've merged the  dev  branch into  master  but actually you wanted to perform a  --no-ff  merge git reset --hard origin/master  #  to undo the above merge : reset the master branch to the pre-merge state git merge --no-ff -m 'my custom merge message' dev # now you can perform the merge you actually wanted To  undo an already pushed merge , you have to "git reset --hard ' the preceding commit ID of your last push to the master branch '" and repush the newly created commit using the  -f  flag.

Go on GAE: Auto-reload / refresh of HTML templates using the template pkg

If you wonder why the changes in your template.html aren't reflected on the server and whether  it's not a bug  — ...no, it's a feature... ;)   The  solution to reparase your HTML template  — at least while you're in dev mode — is to appropriately incorporate this code snippet into your app.   var myTemplate = template.MustParseFile("template.html", nil)  func reparseHTMLtemplate(w http.ResponseWriter, r *http.Request) { myTemplate, err = template.ParseFile("template.html", nil)  fmt.Fprintln(w, "reloaded / refreshed / reparsed:", err)  }   Thanks to  Andrew Gerrand  for this solution!

Go: Read / Print the content of files — the simplest way

The easiest way to get the content (as a string) of a file in Go is: import "io/ioutil" //[..] content, err :=  ioutil.ReadFile ("./myDirectory/myFile.txt") fmt.Println(string(content)) fmt.Print(err)

Go compiler spec explanation for "Compile error: val declared and not used"

I you get this compiler error, it's because you have declared a variable that isn't used anywhere in your code. Just use this variable by doing something like fmt.Println(yourVal) The analogon for imported and not (yet) used packages is (in this case for the  fmt  package) var _ = fmt.Printf // delete before submitting  But much more interesting is  Rob's explanation for this Go spec decision to let the compiler report "val declared and not used" as an error and not a warning .

Hg / Mercurial Warning: "not verified (check hostfingerprints or web.cacerts config setting)"

Mac Solution: openssl req -new -x509 -extensions v3_ca -keyout /dev/null -out dummycert.pem -days 3650 sudo cp dummycert.pem /etc/hg-dummy-cert.pem Add this [web] cacerts = /etc/hg-dummy-cert.pem ...to  ~/.hgrc Here you can find the  solutions for other OS like Windows or Linux .

Git: Lightweight tags VS annotated tags

There are a two main types of tags in Git - lightweight and annotated. Lightweight tags are very much like branches that don’t change - it’s just a pointer to a specific commit. Annotated tags, however, are stored as full objects in the Git database. They are checksummed, contain the tagger name, email and date, have a tagging message and can be GPG signed and verified. It’s generally recommended to create annotated tags so you can have all this information, but if you want a temporary tag or for some reason don’t want to keep that other information, lightweight tags are available too.  -- GitHub Create a lightweight Git tag: git tag TagName Create an annotated Git tag: git tag -a -m 'optional tag comment' TagName (If you omit the  -a  flag but still add a comment using  -m , you're still creating an annotated tag!) List Git tags: git tag Show Git tag content: git show TagName Delete a Git tag: git tag -d TagName

Named result parameters / values in Go

In this example func WebCmd(cmd string)  (restCall string)  { m := map[string]string{ "c":   " https://mail.google.com/mail/?shva=1#compose ", "t":   " http://twitter.com ", "lox": " https://github.com/loxal/Lox ", } restCall = m[cmd] return } restCall  is the named  return parameter  of type string and  cmd is the unnamed parameter  required to call the WebCmd  function. Within the  WebCmd  function the string value of  m[cmd]  is assigned to the  restCall  variable which is returned by the  WebCmd  function.

Want Vi / Vim on your Bash command line

Put set -o vi  into your  ~/.bash_profile  (on Mac) or  ~/.bashrc  (on Linux).  Now, if you press  Esc  when you're on the command line, you can go backward/forward word-wise pressing B  resp.  W  or bring-up Vim's  VISUAL mode  pressing  V . After pressing  Esc  you can press  I  to get back to the  INSERT mode  to modify your command.

Go: Get Query Parameters From the URL / URI

The low-API approach isn't to use the  web package  but the  http package  to accomplish this. http://localhost:8080/cmd?foo=My_Param_Value&bar=Query_Parameters // .. import http // .. func cmd(w http.ResponseWriter, r *http.Request) {     c := appengine.NewContext(r)     c.Logf("r.URL.Path: " + r.URL.Path)     c.Logf("r.FormValue(\"foo\"): " +  r.FormValue("foo") )     c.Logf(r.FormValue("bar"))     c.Logf("r.URL.RawQuery: " + r.URL.RawQuery) } // .. ...and the output is:   2011/05/14 12:26:11 r.URL.Path: /cmd 2011/05/14 12:26:11 r.FormValue("foo"): My_Param_Value 2011/05/14 12:26:11 query_parameters 2011/05/14 12:26:11 r.URL.RawQuery: foo=My_Param_Value&bar=query_parameters

Using GWT 2.3 SDK with Maven's GWT plugin 2.2.0

            <plugin>                 <groupId>org.codehaus.mojo</groupId>                 <artifactId>gwt-maven-plugin</artifactId>                 <version>2.2.0</version>                 <configuration>                     <modules>                         <module>dp.verp.view.availability.Availability</module>                     </modules>                     <runTarget>/availability/index.html</runTarget>                 </configuration>                 <executions>                     <execution>                         <goals>                             <goal>resources</goal>                             <goal>compile</goal>                         </goals>                     </execution>                 </executions> <!-- This is probably what you're missing -->                 <dependencies>                    

Changing the actively used Python version on a Mac

To change the current Python version you're using: defaults write com.apple.versioner.python Version  2.5

Using Pandora or Google's Music outside U.S.

If you're in Germany, UK, Austria, Australia, France, Italy, Russia, Japan, Spain or wherever except the United States,  you can't use services like Pandora  or the newly launched  Music (Beta) service from Google . Also some YouTube content might be blocked in your country.   If you are eligible  to access these services and all those YouTube videos, you could try  Tor .  Specifying an  US located server in the  torrc configuration file  as the  ExitNode  and setting  localhost:8118  in your  browser as your proxy for HTTP and HTTPS , will enable you to access all those services. You can find an US located server using Tor's resp. Vidalia's " View the Network"  button.