Instantly share code, notes, and snippets.

View different.rb
hhash = {}
(0..10000000).each{ |i| hhash[i] = rand };
parallel_sum = Parallel.map(hhash.each_slice(1000)) do |ele| # https://github.com/grosser/parallel
ele.sum{|value| value.last}
end.sum
puts parallel_sum
View index.js
// dependencies
var async = require('async');
var AWS = require('aws-sdk');
var gm = require('gm')
.subClass({ imageMagick: true }); // Enable ImageMagick integration.
var util = require('util');
// constants
var MAX_WIDTH = 100;
var MAX_HEIGHT = 100;
View custom_tags.py
# reference: https://docs.djangoproject.com/en/1.6/howto/custom-template-tags/
@register.filter
def get_index(l, element):
return l.index(element)
View models.py
class MyUserManager(BaseUserManager):
def create(self, email, name, birthday, sex, password):
return self.create_user(email=email,
password=password,
name=name,
birthday=birthday,
sex=sex,
)
def create_user(self, email, name, birthday, sex, password):
View gist:9502341
$ python setup.py install
Extracting in /var/folders/yc/w0fp9t155fq6zwvlhf2btx340000gn/T/tmpsKtOqW
Now working in /var/folders/yc/w0fp9t155fq6zwvlhf2btx340000gn/T/tmpsKtOqW/distribute-0.6.28
Building a Distribute egg in /Users/hgkim/Downloads/MySQL-python-1.2.4b4
Traceback (most recent call last):
File "setup.py", line 220, in <module>
scripts = scripts,
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/distutils/core.py", line 112, in setup
_setup_distribution = dist = klass(attrs)
File "/private/var/folders/yc/w0fp9t155fq6zwvlhf2btx340000gn/T/tmpsKtOqW/distribute-0.6.28/setuptools/dist.py", line 225, in __init__
View gist:9484363
$ pip install MySQL-python==1.2.5
Downloading/unpacking MySQL-python==1.2.5
Using download cache from /Users/hgkim/.cache/pip/https%3A%2F%2Fpypi.python.org%2Fpackages%2Fsource%2FM%2FMySQL-python%2FMySQL-python-1.2.5.zip
Running setup.py (path:/Users/hgkim/.virtualenvs/advance/build/MySQL-python/setup.py) egg_info for package MySQL-python
Installing collected packages: MySQL-python
Running setup.py install for MySQL-python
building '_mysql' extension
cc -fno-strict-aliasing -fno-common -dynamic -arch x86_64 -arch i386 -g -Os -pipe -fno-common -fno-strict-aliasing -fwrapv -mno-fused-madd -DENABLE_DTRACE -DMACOSX -DNDEBUG -Wall -Wstrict-prototypes -Wshorten-64-to-32 -DNDEBUG -g -fwrapv -Os -Wall -Wstrict-prototypes -DENABLE_DTRACE -arch x86_64 -arch i386 -pipe -Dversion_info=(1,2,5,'final',1) -D__version__=1.2.5 -I/usr/local/Cellar/mysql/5.6.16/include/mysql -I/System/Library/Frameworks/Python.framework/Versions/2.7/include/python2.7 -c _mysql.c -o build/temp.macosx-10.9-intel-2.7/_mysql.o -Os
View models.py
from django.db import models
class Question(models.Model):
contents = models.TextField()
class Answer(models.Model):
contents = models.TextField()
question = models.ForeignKey(Question)
View models.py
class MyUserManager(BaseUserManager):
def create(self, email, name, birthday, sex, password):
return self.create_user(email=email,
password=password,
name=name,
birthday=birthday,
sex=sex,
)
def create_user(self, email, name, birthday, sex, password):
View serializers.py
class UserSerializer(serializers.HyperlinkedModelSerializer):
password2 = serializers.CharField()
class Meta:
model = VomUser
fields = ('url', 'id', 'email', 'sex', 'birthday',
'name', 'password', 'password2')
read_only_fields = ('email',)
def __init__(self, *args, **kwargs):
View models.py
class MyUserManager(BaseUserManager):
def create(self, email, name, birthday, sex, password):
return self.create_user(email=email,
password=password,
name=name,
birthday=birthday,
sex=sex,
)
def create_user(self, email, name, birthday, sex, password):