Skip to content

Instantly share code, notes, and snippets.

View milovtim's full-sized avatar

Timur milovtim

  • MTVv
  • Saint-Petersburg
View GitHub Profile
@milovtim
milovtim / curl.md
Last active November 14, 2018 12:59

curl often used options

  • -X {method} where method is {GET,POST,HEAD,etc.} (Default: GET)
  • -v verbose mode
  • -o to_file/-O save output to_file or use server-provided filename
    • -J use filename from header
  • -L follow Location header when 3xx code returns
  • -#/--progress-bar use simple progress bar (single-line) instead of default download info
  • -s silent mode
import groovy.transform.Canonical
import java.util.concurrent.CompletableFuture
import java.util.function.Function
import java.util.function.Supplier
final long serviceExecutionTime = 1000
def rand = new Random()
def initVal = rand.nextInt(100)
import java.util.concurrent.CompletableFuture
import java.util.concurrent.TimeUnit
import java.util.function.Supplier
Supplier treeItemSupp = { sleep(50); '`treeItem`' }
Supplier eventItemSupp = { sleep(100); ' `event`'; new RuntimeException('bam!') }
Supplier l10nItemSupp(String treeItem) { return {sleep(200); " `l10n($treeItem)`"} as Supplier }
CompletableFuture.supplyAsync(treeItemSupp)
.thenCompose({ str ->
@milovtim
milovtim / pom.xml
Last active April 8, 2019 14:34
[retired, prefer gmavenplus] maven-compiler-plugin-groovy-compilation
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.5.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
<compilerId>groovy-eclipse-compiler</compilerId>
<verbose>false</verbose>
</configuration>
@milovtim
milovtim / table.filter.lua
Created March 16, 2018 11:43 — forked from FGRibreau/table.filter.lua
Lua table.filter (JavaScript Array::filter equivalent)
-- table.filter({"a", "b", "c", "d"}, function(o, k, i) return o >= "c" end) --> {"c","d"}
--
-- @FGRibreau - Francois-Guillaume Ribreau
-- @Redsmin - A full-feature client for Redis http://redsmin.com
table.filter = function(t, filterIter)
local out = {}
for k, v in pairs(t) do
if filterIter(v, k, t) then out[k] = v end
end
@milovtim
milovtim / SpringContextHierarchy.groovy
Last active January 15, 2018 14:46
Demonstration on bean definitions inheritanse between parent-child contexts
import org.springframework.context.annotation.Bean
import org.springframework.context.annotation.Configuration
import org.springframework.context.support.GenericGroovyApplicationContext
interface ServiceInParent {
String invokeParent()
}
class ChildService {
ServiceInParent serviceInParent
@milovtim
milovtim / spring-integration-sample.groovy
Created November 29, 2017 10:55
Simple context to check spring-integration components
import org.springframework.context.support.GenericXmlApplicationContext
import org.springframework.core.io.ByteArrayResource
import org.springframework.integration.support.MessageBuilder
import org.springframework.messaging.MessageChannel
def xml = '''<?xml version="1.0" encoding="UTF-8"?>
<bean:beans xmlns="http://www.springframework.org/schema/integration"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:bean="http://www.springframework.org/schema/beans"
@milovtim
milovtim / get-file-column.bash
Created November 10, 2017 09:55
Fetch columnd from (log) file. This example was used for tomcat access log
FILE=''
FILTER_EXPR=''
DELIM=' '
# col num -- 3, change if need another
cat $FILE |grep $FILTER_EXPR|awk -F"$DELIM" '{print $3}'|sort|uniq -c> result.txt
@milovtim
milovtim / guava-tree-traversal.groovy
Created November 8, 2017 16:29
Example of guava TreeTraversal. Iterations: breadthFirst, depthFirst (pre-order, post-order)
import com.google.common.collect.TreeTraverser
// format (id/parentId)
def data = [
'1/0',
'2/1', '3/1',
'4/2', '5/2', '6/3',
'7/5', '8/5', '9/6'
]
@milovtim
milovtim / git-branch-remote-delete.bash
Last active November 3, 2017 09:31
List remote git branches. Grep the list by some regexp. get the branch name from result (without 'origin/' prefix). Ask git to delete remote branch by name
git branch --list -r |
grep -P "SOME_REGEXP" |
while read line;
do
IFS="/" read -r -a arr <<< "$line";
git push origin --delete "${arr[1]}";
done