Skip to content

Instantly share code, notes, and snippets.

@ktraff
ktraff / sublime-keymap-escape-blocks.json
Last active June 3, 2021 19:18
Tab key to escape parentheses, quotes, or brackets in Sublime Text
// tab escape parenthesis, quotes, etc...
{ "keys": ["tab"], "command": "move", "args": {"by": "characters", "forward": true}, "context":
[
{ "key": "preceding_text", "operator": "regex_contains", "operand": "[^ \t]+", "match_all": true },
{ "key": "following_text", "operator": "regex_contains", "operand": "^[)'\"\\]]", "match_all": true },
{ "key": "auto_complete_visible", "operator": "equal", "operand": false },
// prevent tab escape when cycling through snippet fields
{ "key": "has_next_field", "operator": "equal", "operand": false }
]
}
@ktraff
ktraff / sublime-text-2-keymap.json
Last active December 14, 2015 22:59
My Sublime Text 2 keymap. Simple but powerful.
[
// auto-indentation shortcut
{ "keys": ["f9"], "command": "reindent"},
// tab escape parenthesis, quotes, etc...
{ "keys": ["tab"], "command": "move", "args": {"by": "characters", "forward": true}, "context":
[
{ "key": "preceding_text", "operator": "regex_contains", "operand": "[^ \t]+", "match_all": true },
{ "key": "following_text", "operator": "regex_contains", "operand": "^[)'}\"\\]]", "match_all": true },
{ "key": "auto_complete_visible", "operator": "equal", "operand": false },
// prevent tab escape when cycling through snippet fields
@ktraff
ktraff / sublime-text-2-user-settings.json
Created March 21, 2013 15:12
My Sublime Text 2 user settings.
{
"auto_complete": false,
"color_scheme": "Packages/Color Scheme - Default/Solarized (Light).tmTheme",
"font_size": 10,
"ignored_packages":
[
"ASP",
"Wordpress",
"TrailingSpaces"
],
@ktraff
ktraff / fb.html
Created April 6, 2013 20:35
Feedback Button HTML Markup
<div id="feedback">
<a href="#">
<img src="http://mediaformations.com/examples/images/feedback.png" alt="" />
</a>
</div>
@ktraff
ktraff / fb.css
Created April 6, 2013 20:40
Feedback Button CSS
#feedback a{
background:green;
display:block;
border:1px solid #030;
border-left-color:#060;
border-top-color:#090;
padding:7px 5px;
position:fixed;
top:200px;
right:-1px;
$("#hide").click(function() {
$("#feedback").hide('slow', function() {
alert('Feedback toggled.'); //add some logic here
});
});
$("#display").click(function()
$("#feedback").show('slow', function() {
alert('Feedback toggled.'); //add some logic here
});
@ktraff
ktraff / mmwh1.java
Created April 6, 2013 21:18
maintaining the median with heaps 1
minHeap = new PriorityQueue();
maxHeap = new PriorityQueue(1, new MaxIntComparator());
@ktraff
ktraff / mmwh2.java
Created April 6, 2013 21:27
maintain the median with heaps 2
import java.util.Comparator;
public class MaxIntComparator implements Comparator {
@Override
public int compare(Integer o1, Integer o2) {
return o2 - o1;
}
}
@ktraff
ktraff / mmwh3.java
Created April 6, 2013 21:35
maintain the median with heaps 3
public double findMedian(int[] arr)
{
double median = Integer.MAX_VALUE;
for(int i=0;i<arr.length;i++)
{
adjustHeaps(median);
if(arr[i] <= median)
{
maxHeap.add(arr[i]);
}
@ktraff
ktraff / mmwh4.java
Created April 6, 2013 21:36
maintain the median with heaps 4
public double getMedian() {
int size = minHeap.size() + maxHeap.size();
double median = Integer.MAX_VALUE;
if(size % 2 == 0)
{
if(!minHeap.peek()) median = maxHeap.peek();
else if(!maxHeap.peek()) median = minHeap.peek();
else median = ((double) minHeap.peek() + maxHeap.peek()) / 2;
}
else