Skip to content

Instantly share code, notes, and snippets.

View valyagolev's full-sized avatar
💭
hey there! i'm using github

Valentin Golev valyagolev

💭
hey there! i'm using github
View GitHub Profile
@valyagolev
valyagolev / Instructions.markdown
Created August 18, 2011 19:33
Virtualenv in new Terminal windows/tabs

Run these commands in your console, they will edit necessary files:

echo 'basename "$VIRTUAL_ENV" > ~/.last_venv' >> $VIRTUALENVWRAPPER_HOOK_DIR/postactivate
echo 'rm ~/.last_venv' >> $VIRTUALENVWRAPPER_HOOK_DIR/postdeactivate

Then open your ~/.bashrc or ~/.profile or whatever your shell uses and append:

if [ -e ~/.last_venv ]; then
    workon `cat ~/.last_venv`

fi

@valyagolev
valyagolev / ps.py
Created May 5, 2011 04:45
PermitedSet
class PermitedSet(object):
"""Acts like a set of users and groups who can use an object
other_perms are permissions which should be
added and revoked with the first one
Usage in model:
@property
@valyagolev
valyagolev / app1.search_indexes.py
Created May 4, 2011 05:24
django-haystack is annoying
from search_sites import register_model_for_search
from .models import CoolModel
register_model_for_search(CoolModel)
@valyagolev
valyagolev / __init__.py
Created April 29, 2011 02:46
Django settings awesomness
from .base import *
try:
from .local import *
except ImportError:
pass
Traceback (most recent call last):
File "./manage.py", line 15, in <module>
execute_manager(settings)
File "/usr/local/lib/python2.6/dist-packages/django/core/management/__init__.py", line 438, in execute_manager
utility.execute()
File "/usr/local/lib/python2.6/dist-packages/django/core/management/__init__.py", line 379, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/usr/local/lib/python2.6/dist-packages/django/core/management/base.py", line 191, in run_from_argv
self.execute(*args, **options.__dict__)
File "/usr/local/lib/python2.6/dist-packages/django/core/management/base.py", line 220, in execute
/media/oldroot/home/valentin/Work/buzzoola/buzzoola/chef-repo
[.../chef-repo]$ knife ssh "role:frontend" "uptime"
WARN: Failed to connect to node[i-226c9f4d] -- SocketError: getaddrinfo: Name or service not known
WARN: Failed to connect to node[i-ee50a381] -- SocketError: getaddrinfo: Name or service not known
__________________
/media/oldroot/home/valentin/Work/buzzoola/buzzoola/chef-repo
[.../chef-repo]$ knife ssh "role:frontend" "uptime" -a "cloud.public_ips[0]"
FATAL: No nodes returned from search!
__________________
/media/oldroot/home/valentin/Work/buzzoola/buzzoola/chef-repo
[.../chef-repo]$ knife role list
[
"database",
"frontend",
"worker"
]
__________________
@valyagolev
valyagolev / localized_models.py
Created November 10, 2010 03:16
Localized Models generator
# -*- coding: utf-8 -*-
from django.db import models
from django.contrib import admin
from copy import copy
LANGUAGES = ((2, 'Английский'),)
class LocalizedModel(models.Model):
language = models.IntegerField('язык', choices=LANGUAGES, default=2)
// pe205.cpp: определяет точку входа для консольного приложения.
//
#include "stdafx.h"
int* add_one(int* brs, int max, int count) {
for (int i = count-1; i >= 0; i--) {
if (brs[i] < max) {
brs[i]++;
for (int j = i+1; j < count; j++) {
import List (sortBy)
isInteger :: Rational -> Bool
isInteger x = (toRational (truncate x)) == x
isQuad :: (Floating a, Real a) => a -> Bool
isQuad x = isInteger (toRational (sqrt x))
findMinX :: (Floating a, Real a, Enum a) => a -> a