Skip to content

Instantly share code, notes, and snippets.

View nilcolor's full-sized avatar
💫
API by day, IPA by night

Alexey Blinov nilcolor

💫
API by day, IPA by night
View GitHub Profile
(function($, window, document, undefined){
//handy log function
window.log = function(){
log.history = log.history || [];
log.history.push(arguments);
if(this.console)
console.log( Array.prototype.slice.call(arguments) );
};
$.extend($.expr[':'], {
@nilcolor
nilcolor / gist:790443
Created January 21, 2011 21:18
Set Emacs default frame size
(defun set-frame-size-according-to-resolution ()
(interactive)
(if window-system
(progn
;; use 180 char wide window for largeish displays
;; and smaller 80 column windows for smaller displays
;; pick whatever numbers make sense for you
(if (> (x-display-pixel-width) 1280)
(add-to-list 'default-frame-alist (cons 'width 180))
(add-to-list 'default-frame-alist (cons 'width 80)))
@nilcolor
nilcolor / gist:812487
Created February 5, 2011 14:29
Node.js pristine server template
var http = require('http'),
url = require('url'),
qs = require('querystring');
var paths = {
'__default__': function (req, res) {
console.log('noop');
res.writeHead(200, {'Content-Type': 'text/plain'});
res.end();
},
@nilcolor
nilcolor / Node.js CORS
Created February 8, 2011 15:28
Node.js cross-origin POST. You should response for OPTIONS request first. Something like this.
if (req.method === 'OPTIONS') {
console.log('!OPTIONS');
var headers = {};
// IE8 does not allow domains to be specified, just the *
// headers["Access-Control-Allow-Origin"] = req.headers.origin;
headers["Access-Control-Allow-Origin"] = "*";
headers["Access-Control-Allow-Methods"] = "POST, GET, PUT, DELETE, OPTIONS";
headers["Access-Control-Allow-Credentials"] = false;
headers["Access-Control-Max-Age"] = '86400'; // 24 hours
headers["Access-Control-Allow-Headers"] = "X-Requested-With, X-HTTP-Method-Override, Content-Type, Accept";
@nilcolor
nilcolor / gist:1031338
Created June 17, 2011 12:36
JavaScript vs Python
//JavaScript
function _A(num){
var o = {};
o.a = num;
o.square = function(){
return o.a * o.a;
};
return o;
@nilcolor
nilcolor / views.py
Created October 12, 2011 13:56
@view_config
class FuckyView(object):
def __init__(self, request):
self.request = request
@view_config(context="starter.resources.Bar")
def fucky(request):
return Response('fucky view')
@nilcolor
nilcolor / speetter.py
Created October 20, 2011 19:09 — forked from bobuk/speetter.py
Говорилка
# -*- coding: utf-8 -*-
# получить twitter можно командой `pip install twitter`
import sys;reload(sys);sys.setdefaultencoding('utf-8')
import twitter
import time
import commands, itertools
consumer_key = ...
consumer_secret = ...
access_key = ...
@nilcolor
nilcolor / →GReader
Created November 8, 2011 07:25
Bookmarklet that helps you to subscribe for current site's RSS in Google Reader
javascript:var%20b=document.body;var%20GR________bookmarklet_domain='http://www.google.com';if(b&&!document.xmlVersion){void(z=document.createElement('script'));void(z.src='http://www.google.com/reader/ui/subscribe-bookmarklet.js');void(b.appendChild(z));}else{location='http://www.google.com/reader/view/feed/'+encodeURIComponent(location.href)}
@nilcolor
nilcolor / gist:1393643
Created November 25, 2011 14:30
ido-find-file
;; use ido for minibuffer completion
(require 'ido)
(ido-mode t)
(setq ido-save-directory-list-file "~/.emacs.d/.ido.last")
(setq ido-enable-flex-matching t)
(setq ido-use-filename-at-point 'guess)
(setq ido-show-dot-for-dired t)
@nilcolor
nilcolor / .ackrc
Created April 13, 2012 09:06
ack[_grep] setup
#~/.ackrc
--type-add
html=.erb,.haml,.jade
--type-set
scripts=.js,.coffee
--type-set
styles=.css,.scss,.sass,.less
--ignore-dir=node_modules
--ignore-dir=vendor # you still can ack in vendor files - just `cd vendor && ack ...`