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
#After looking for a way to check if a model instance can be deleted in django , | |
#i came across many sample, but was not working as expected. Hope this solution can help. | |
#Let start by creating an Abstract model class which can be inherited by other model | |
class ModelIsDeletable(models.Model): | |
name = models.CharField(max_length=200, blank=True, null=True, unique=True) | |
description = models.CharField(max_length=200, blank=True, null=True) | |
date_modified = models.DateTimeField(auto_now_add=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
#!/usr/bin/env python | |
import boto | |
import sys, os | |
from boto.s3.key import Key | |
from boto.exception import S3ResponseError | |
DOWNLOAD_LOCATION_PATH = os.path.expanduser("~") + "/s3-backup/" | |
if not os.path.exists(DOWNLOAD_LOCATION_PATH): |
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
// number to string, pluginized from http://stackoverflow.com/questions/5529934/javascript-numbers-to-words | |
window.num2str = function (num) { | |
return window.num2str.convert(num); | |
} | |
window.num2str.ones=['','one','two','three','four','five','six','seven','eight','nine']; | |
window.num2str.tens=['','','twenty','thirty','forty','fifty','sixty','seventy','eighty','ninety']; | |
window.num2str.teens=['ten','eleven','twelve','thirteen','fourteen','fifteen','sixteen','seventeen','eighteen','nineteen']; |
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
//how i started understanding my javascript oop concept based on ES5 | |
//welcome comment and and | |
var Bank = function(name,acct_bal){ | |
this.name = name; this.acct_bal = acct_bal; | |
} | |
Bank.prototype.deposit = function(amount){ | |
this.acct_bal += amount; | |
console.log("Deposited =$" + amount + "\nYour balance is $" + this.acct_bal); | |
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
DIR_TO_UPLOAD = 'project-dist' | |
def upload_percent_cb(complete, total): | |
sys.stdout.write('-') | |
sys.stdout.flush() | |
def remove_root_dir_from_path(c): | |
s = c.split('/') | |
s.remove(DIR_TO_UPLOAD) |
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 functools import update_wrapper | |
from django.contrib import admin | |
from django.contrib.admin import ModelAdmin | |
from django.contrib.admin.templatetags.admin_urls import add_preserved_filters | |
from django.core.exceptions import PermissionDenied | |
from django.shortcuts import render | |
from myapp.models import Widget | |
from myapp.forms import ManageWidgetForm |
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 shouldStoreDouble: Double = 200.0 // we restrict this by adding an annotation | |
print("Double annotation ", shouldStoreDouble); | |
// let see when we say our computer should create | |
// a memory space for string but we try to store an integer | |
var onlyStringPlease: String = "John" | |
print("String annotation ", onlyStringPlease) |
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
Source : https://developers.google.com/web-toolkit/doc/latest/DevGuideCompilingAndDebugging | |
java -cp gwt-dev.jar com.google.gwt.dev.Compiler | |
Missing required argument 'module[s]' | |
Google Web Toolkit 2.3.0 | |
Compiler [-logLevel level] [-workDir dir] [-gen dir] [-style style] [-ea] [-XdisableClassMetadata] [-XdisableCastChecking] [-validateOnly] [-draftCompile] [-optimize level] [-compileReport] [-strict] [-localWorkers count] [-war dir] [-deploy dir] [-extra dir] module[s] | |
where | |
-logLevel The level of logging detail: ERROR, WARN, INFO, TRACE, DEBUG, SPAM, or ALL | |
-workDir The compiler's working directory for internal use (must be writeable; defaults to a system temp dir) |
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 flatten_array(arr): | |
output = [] | |
for val in arr: | |
if type(val) == list: # is the current value we are looking at is also a list | |
output.extend(flatten_array(val)) # then recursive call itself to start from | |
# the beginning and use python list extend | |
else: | |
output.append(val) # ok this is not a list just append to the bottom | |
return output |
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 myResponse = {"start_date":["A valid integer is required."], | |
"end_date":["A valid integer is required."], "commite":["Require commite."]} | |
//iterate over the serializer error message | |
for (var prop in myResponse) { | |
var errorValue = myResponse[prop]; | |
//test if the current prop has an _ in it string value | |
var _pattern = /_/; | |
if (_pattern.test(prop)) { |
NewerOlder