Skip to content

Instantly share code, notes, and snippets.

class User < ActiveRecord::Base
define_index do
set_property enable_star: true
indexes :name
indexes :phone
indexes :address
end
def self.query(options)
@kates
kates / copypaste.vim
Created September 6, 2013 09:38
vim copy/paste to system clipboard
let os = substitute(system('uname'), "\n", "", "")
if os == "Darwin"
vmap <C-c> y:call system("pbcopy", getreg("\""))<CR>:echo "copied to system clipboard"<CR>
nmap <C-v> :call setreg("\"", system("pbpaste"))<CR>p:echo ""<CR>
end
@kates
kates / crosshair.vim
Created September 6, 2013 09:34
Hide cursorcolum and cursorline in inactive window
augroup CrossHair
au!
au VimEnter * setlocal cursorline
au WinEnter * setlocal cursorline
au BufWinEnter * setlocal cursorline
au WinLeave * setlocal nocursorline
au VimEnter * setlocal cursorcolumn
au WinEnter * setlocal cursorcolumn
au BufWinEnter * setlocal cursorcolumn
@kates
kates / yamlstr.py
Created August 12, 2013 04:05
Double quoting YAML keys and scalar values
import argparse
from yaml import load, dump, add_representer
try:
from yaml import CDumper as Dumper
except ImportError:
from yaml import Dumper
def rep(dumper, data):
return dumper.represent_scalar('tag:yaml.org,2002:str', data, style=None)
@kates
kates / search_and_replace.sh
Last active August 31, 2019 05:22
bulk search and replace with the silver searcher, awk, sed and xargs
ag "sometext" --nogroup | awk '{print substr($1,1,index($1,":")-1);}' | xargs -I {} sed -i .bak -e 's/sometext/anothertext/g' {}
@kates
kates / .tmux.conf
Last active December 19, 2015 00:59
tmux conf
unbind C-b
set -g prefix C-a
bind C-a send-prefix
set-window-option -g mode-keys vi
set -g mode-mouse off
set -g mouse-select-pane off
set -g mouse-resize-pane off
set -g mouse-select-window off
set-option -g default-command "reattach-to-user-namespace -l bash"
@kates
kates / index_1.html
Last active December 11, 2015 04:19
optimizing js
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<script type="text/javascript">
function add(){
for (var i = 0; i < 500; i++) {
$('<div style="background-color: #A68585;margin: 2px 0;width: 100px;height: 30px;">' + i + '</div>').appendTo('.box');
}
}
@kates
kates / variadic.js
Created November 20, 2012 01:50
thin layer on top of when.js
(function(buster, when, apply) {
var assert, refute, fail, sentinel;
assert = buster.assert;
refute = buster.refute;
fail = buster.assertions.fail;
sentinel = {};
@kates
kates / api.md
Created October 23, 2012 02:57
sample dox output

Component#toString()

  • Generates string representation of this object
    • @returns Combination displayName and instanceCount

eventProxy()

@kates
kates / doxer.js
Created October 22, 2012 06:58
grunt config is missing in tasks using grunt.loadTasks
module.exports = function(grunt) {
grunt.registerTask("doxer", "Generate docs", function() {
grunt.log.writeln("generator: " + this.generator); // <-- this.generator is undefined
});
};