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
license: MIT |
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
Not sure if it is designed this way but it is wierd that the @Resource annotation doesn't work with generated scaffolding (generate-all). | |
It is easy to have 2 controller serving 1 domain class, but not ideal. | |
Evan's answer @ http://stackoverflow.com/questions/19465421/how-to-use-scaffolding-and-restfulness-together-in-grails-2-3 works. | |
It's a bit more work but the only 1 controller is needed | |
Note: will need a entry point (linking to the same controller) |
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
var Person = { | |
name: 'Joe', | |
hello() { | |
console.log('Hello, my name is', this.name); | |
} | |
}; | |
[1,2,3].map(x => x * x); |
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 doSomething() { | |
let N = 5; | |
if (someCondition) { | |
let N = 10; | |
doSomethingElse(N); | |
} | |
console.log(N); // 5 | |
} |
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 inc(x, y = 1) { return x += y; } |
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
for (var i = 0, item; item = a[i++];) { | |
// Do something with item | |
} |
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
DOMAIN CLASS (Post): | |
String timeDay | |
Date date | |
static mapping = { | |
timeDay formula: "FORMATDATETIME(date, 'yyyy-MM-dd')" // h2 sql | |
//timeMonth formula: "DATE_FORMAT(time, '%Y-%m-%d')" // mysql sql | |
} | |
CONTROLLER: | |
def c = Post.createCriteria() |
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
def getImageFromUrl(String url) { | |
println "getting image from url: " + url | |
if (!url) return null | |
def document | |
try { | |
document = Jsoup.connect(url).get() | |
def imgStr = getMetaTag(document, "twitter:image") | |
if (!imgStr) imgStr = getMetaTag(document, "og:image") | |
return imgStr | |
} catch (Exception e) { |
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 grails.converters.JSON | |
JSON.use('deep') | |
render(contentType: 'text/json') {[ | |
'results':results, | |
'status': results ? "200" : "500" | |
]} |