Skip to content

Instantly share code, notes, and snippets.

View olegchir's full-sized avatar

Oleg Chirukhin olegchir

View GitHub Profile
@olegchir
olegchir / gitcheats.txt
Created December 4, 2017 12:09 — forked from chrismccoy/gitcheats.txt
git cheats
# shortform git commands
alias g='git'
# get a list of all commit messages for a repo
git log --pretty=format:'%s'
# push changes to an empty git repository for the first time
git push --set-upstream origin master
# Remove + and - from start of diff lines
#pragma once
class FakeInt {
public:
FakeInt(int value)
: value(value)
{
}
operator int() const
@SpringBootApplication
@EnableTask
public class SampleTask {
@Bean
public CommandLineRunner commandLineRunner() {
return new HelloWorldCommandLineRunner();
}
public static void main(String[] args) {
SQLClientHelper.inTransactionSingle(client, sqlConnection -> {
return sqlConnection.rxExecute("INSERT INTO albums (name) VALUES ('The Israelites')")
.andThen(sqlConnection.rxExecute("INSERT INTO tracks (album, name) VALUES ('The Israelites', 'Israelites')"))
.andThen(sqlConnection.rxExecute("INSERT INTO tracks (album, name) VALUES ('The Israelites', 'Too Much Too Soon')"))
.andThen(sqlConnection.rxQuery("SELECT name FROM tracks WHERE album = 'The Israelites'").map(ResultSet::getResults))
}).map(rows -> {
// Transform DB rows into a client-friendly JSON object
}).subscribe(json -> {
// Send JSON to the client
}, t -> {
rest("/api/")
.id("api-route")
.consumes("application/json")
.post("/bean")
.bindingMode(RestBindingMode.json_xml)
.type(MyBean.class)
.to("direct:remoteService");
//...
def clazz = new MethodCallExpression(new VariableExpression("this"), "getClass", EMPTY_ARGUMENTS)
def body = new ExpressionStatement(new MethodCallExpression(clazz, "getName", EMPTY_ARGUMENTS))
classNode.addMethod('getDescription', ACC_PUBLIC, STRING_TYPE, EMPTY_ARRAY, ClassNode.EMPTY_ARRAY, body)
//До 2.5 приходилось писать так:
def clazz = new MethodCallExpression(new VariableExpression("this"), "getClass", EMPTY_ARGUMENTS)
def body = new ExpressionStatement(new MethodCallExpression(clazz, "getName", EMPTY_ARGUMENTS))
classNode.addMethod('getDescription', ACC_PUBLIC, STRING_TYPE, EMPTY_ARRAY, ClassNode.EMPTY_ARRAY, body)
//После 2.5 первые две строчки превращаются в такое:
def body = macro(true) {
getClass().name
object Config {
var width: Int = 10
private set
init {
val file = fopen("config.txt", "r")
if (file != null) {
try {
val buffer = ByteArray(2 * 1024)
while (true) {
val nextLine = fgets(buffer.refTo(0), buffer.size, file)?.toKString()
object Config {
private val icon_ = AtomicReference<Image>()
val icon: Image
get() = icon_.get()!!
fun updateIcon(file: String) {
val imageData = Image(file)
icon_.compareAndSwap(icon_.get(), imageData.freeze())
}
}
<plugin>
<groupId>com.google.cloud.tools</groupId>
<artifactId>jib-maven-plugin</artifactId>
<version>0.9.6</version>
<configuration>
<to>
<image>gcr.io/my-project/image-built-with-jib</image>
</to>
</configuration>
</plugin>