Skip to content

Instantly share code, notes, and snippets.

@dkandalov
dkandalov / gist:4747666
Created February 10, 2013 00:03
wrapper for Vcs.ShowHistoryForBlock
import com.intellij.execution.ExecutionManager
import com.intellij.execution.Executor
import com.intellij.execution.executors.DefaultRunExecutor
import com.intellij.execution.filters.TextConsoleBuilderFactory
import com.intellij.execution.ui.ConsoleView
import com.intellij.execution.ui.ConsoleViewContentType
import com.intellij.execution.ui.ExecutionConsole
import com.intellij.execution.ui.RunContentDescriptor
import com.intellij.execution.ui.actions.CloseAction
import com.intellij.icons.AllIcons
@dkandalov
dkandalov / gist:4761632
Created February 12, 2013 11:13
AnalysisUtil
class AnalysisUtil {
static def aggregateByDuration = { events -> events.sum(0) { it.duration } }
static def aggregateByQueryDuration = { events -> events.sum(0) { it.queryDuration } }
static def aggregateByAmount = { events -> events.size() }
static def histogramOf(Closure criteria, amountOfIntervals, List lines) {
double maxValue = criteria(lines.max(criteria))
double minValue = criteria(lines.min(criteria))
double intervalSize = (maxValue - minValue) / amountOfIntervals
@dkandalov
dkandalov / 12 years of "TODO"
Last active December 13, 2015 23:59
Beautiful code best practice enterprise patterns
/**
* Insert the method's description here.
* Creation date: (4/16/01 3:47:01 PM)
* @param newHierarchy com.xxxx.xxxxxxxx.reporting.xxxxx.api.datasource.Hierarchy
*/
public void setHierarchy(com.xxxx.xxxxxxxx.reporting.xxxxx.api.datasource.Hierarchy newHierarchy) {
@dkandalov
dkandalov / plugin.groovy
Last active December 14, 2015 01:09
Watch change list size micro-plugin
import com.intellij.notification.NotificationType
import com.intellij.openapi.actionSystem.ActionManager
import com.intellij.openapi.actionSystem.AnAction
import com.intellij.openapi.actionSystem.AnActionEvent
import com.intellij.openapi.application.ApplicationManager
import com.intellij.openapi.diff.impl.ComparisonPolicy
import com.intellij.openapi.diff.impl.fragments.LineFragment
import com.intellij.openapi.diff.impl.processing.DiffPolicy
import com.intellij.openapi.diff.impl.processing.TextCompareProcessor
import com.intellij.openapi.diff.impl.util.TextDiffTypeEnum
@dkandalov
dkandalov / plugin.groovy
Last active January 29, 2022 16:37
Evaluate selection as Groovy
import com.intellij.openapi.editor.Editor
import com.intellij.openapi.project.Project
import org.codehaus.groovy.control.CompilationFailedException
import static liveplugin.PluginUtil.*
// This is micro-plugin for IntelliJ to evaluate selected text as Groovy expression
// (Note that this code can only be executed within this plugin https://github.com/dkandalov/live-plugin)
// You can try it on the following code. Should produce 14.
@dkandalov
dkandalov / gist:5032038
Last active December 14, 2015 04:59
d3 tutorial
// This is code for d3 tutorial at http://ofps.oreilly.com/titles/9781449339739/_drawing_with_data.html
// At some point it turned into completely insane copy-pasting.. please don't try to read this :)
// Do the tutorial yourself instead.
var w = 500;
var h = 300;
var dataset1 = [ 5, 10, 13, 19, 21, 25, 22, 18, 15, 13, 11, 12, 15, 20, 18, 17, 16, 18, 23, 25 ];
var dataset_scatter = [ [ 5, 20 ], [ 480, 90 ], [ 250, 50 ], [ 100, 33 ], [ 330, 95 ], [ 410, 12 ], [ 475, 44 ], [ 25, 67 ], [ 85, 21 ], [ 220, 88 ] ];
var dataset = dataset1;
@dkandalov
dkandalov / gist:5066611
Last active December 14, 2015 09:39
simple d3 script for displaying timebased events from csv
var csv = ""; // paste csv into this string
var margin = {top: 20, right: 20, bottom: 30, left: 50},
width = 960 - margin.left - margin.right,
height = 500 - margin.top - margin.bottom;
var parseFormat = d3.time.format("%H:%M:%S");
var displayFormat = d3.time.format("%H:%M");
var x = d3.time.scale().range([0, width]);
@dkandalov
dkandalov / gist:5129543
Last active December 14, 2015 18:29
Wrap-selection micro plugin for IntelliJ
import static liveplugin.PluginUtil.*
// This is micro-plugin for IntelliJ to wrap long lines with separator.
// E.g. list literal like this [1, 2, 3, 4, ..., 200000] can be split into somewhat more readable
// [1, 2, 3, 4,
// 5, 6, 7, 8
// ..., 200000]
// (Note that this code can only be executed within this plugin https://github.com/dkandalov/live-plugin)
if (isIdeStartup) return
@dkandalov
dkandalov / plugin.groovy
Last active December 14, 2015 21:59
mixin/mixout categories in Groovy
GroovySystem.metaClassRegistry.removeMetaClass(String)
class PrintValueMethodCategory {
static def printValueMethod(String s) {
"The value is: '$s'"
}
}
String.metaClass.mixin(PrintValueMethodCategory)
println('variable B'.printValueMethod())
@dkandalov
dkandalov / plugin.groovy
Last active February 4, 2017 14:47
Wrapping tab action
import com.intellij.openapi.actionSystem.ActionManager
import com.intellij.openapi.actionSystem.AnAction
import com.intellij.openapi.actionSystem.AnActionEvent
import com.intellij.openapi.actionSystem.DataContext
import com.intellij.openapi.editor.Editor
import com.intellij.openapi.editor.actionSystem.DocCommandGroupId
import com.intellij.openapi.editor.actionSystem.EditorAction
import com.intellij.openapi.editor.actionSystem.EditorActionHandler
import com.intellij.openapi.editor.actions.TabAction
import liveplugin.implementation.ActionWrapper