This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# OLD One with error => 'You cannot call create unless the parent is saved' | |
def number_list=(numbers_string) | |
self.numbers.destroy_all | |
numbers = numbers_string.split(",").collect{|num| num.strip.downcase}.uniq | |
numbers.each do |number| | |
num = self.numbers.find_or_create_by_content(number) | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Improved one base on condition, bad coding but it's work! | |
def number_list=(numbers_string) | |
self.numbers.destroy_all | |
numbers = numbers_string.split(",").collect{|num| num.strip.downcase}.uniq | |
numbers.each do |number| | |
unless !self.save | |
num = self.numbers.find_or_create_by_content(number) | |
end | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ActiveRecord::Schema.define(:version => 20110221190024) do | |
create_table "comments", :force => true do |t| | |
t.string "title" | |
t.text "body" | |
t.integer "commentable_id" | |
t.string "commentable_type" | |
t.datetime "created_at" | |
t.datetime "updated_at" | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class UsersController < ApplicationController | |
before_filter :authenticate, :except => [:show, :new, :create] | |
before_filter :correct_user, :only => [:edit, :update] | |
before_filter :admin_user, :only => :destroy | |
def index | |
@title = "All users" | |
@users = User.paginate(:page => params[:page]) | |
end | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <QApplication> | |
#include <QLabel> | |
int main(int argc, char **argv) | |
{ | |
QApplication App(argc, argv); | |
QLabel Lbl("Hello KhoshGel!"); | |
Lbl.show(); | |
App.exec(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var maxfiles = {{ maxfiles }}; // {{ maxfiles }} returns from views.py | |
$(function() { | |
$("#uploader").pluploadQueue({ | |
runtimes : 'gears', // Initialize gears runtime | |
url : '{{ obj.get_image_upload_url }}', // Url to current object image uploading url | |
max_file_size : '4mb', | |
chunk_size: '4mb', | |
multiple_queues : true, | |
multi_selection: false, // It's necessary for file uploading limit | |
rename: true, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@login_required | |
def delete(request, msg_pk): | |
msg = get_object_or_404(Message, pk=msg_pk) | |
## is owner? | |
if request.user != msg.user and request.user != msg.to: | |
raise Http404() | |
# Sender or Receiver ? | |
if msg.delete_status == 2: | |
msg.delete_status = 3 | |
elif request.user == msg.user and request.user != msg.to: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def clean(self): | |
from decimal import Decimal | |
cleaned_data = self.cleaned_data | |
price_mode = cleaned_data.get('price_mode') | |
price = cleaned_data.get('price') | |
if price_mode == u'0': | |
if price: | |
return self.cleaned_data['price'] | |
return self.cleaned_data['price_mode'] | |
else: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django.contrib import admin | |
from django.db import models | |
class Item(models.Model): | |
name = models.CharField(max_length=60) | |
created = models.DateTimeField(auto_now_add=True) | |
priority = models.IntegerField(default=0) | |
difficulty = models.IntegerField(default=0) | |
done = models.BooleanField(default=False) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const std::vector<std::string> toStdVector(const QVector<QString> &q_vect) | |
{ | |
std::vector<string> std_vect; | |
for (int i = 0; i < q_vect.size(); ++i) { | |
std_vect.push_back(q_vect[i].toStdString()); | |
} | |
return std_vect; | |
} |
OlderNewer