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
//simple work arroud on getting a property type using a matcher from an array | |
//welcome any comment and modification / enhacnement | |
var myArray = [{"name" : "pitaside", "id" : 1}, {"name":"github", "id" : 3}] | |
filterArrayByType: function (arrayToMatch, fieldType, matcher) { | |
if(! arrayToMatch instanceof Array){throw ("Not an Array")} | |
var filterTypeToReturn = arrayToMatch.filter((items) => { | |
var temp; | |
if (items[String(fieldType)] === matcher) { | |
temp = items[String(fieldType)] |
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
/* | |
Please feel free to comment and any advice | |
* Created by peter | |
*/ | |
var Person = {} | |
// an empty person object | |
//sample json object, can also be from a server | |
var sampleJson = {'name': 'Peter', 'age': "20"}; |
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 InputComponent = React.createClass({ | |
propTypes: { | |
type: React.PropTypes.string, | |
placeholder: React.PropTypes.string, | |
id: React.PropTypes.string, | |
classStyle: React.PropTypes.string, | |
defaultVal: React.PropTypes.oneOfType([ | |
React.PropTypes.string, | |
React.PropTypes.number |
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 App extends React.Component { | |
static propTypes = { | |
params: PropTypes.object.isRequired, | |
}; | |
state = { | |
.... | |
}; | |
componentWillMount() { |
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 myObjArray = [ | |
{ | |
name: 'peter', | |
age: 25 | |
}, | |
{ | |
name: 'john', | |
age: 15 |
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
import org.apache.commons.codec.binary.Base64; | |
import java.security.SecureRandom; | |
/** | |
* Created by pitaside on 7/12/2015. | |
*/ | |
public class RandomURLKeyGenerator { | |
public static String generateURLKey(int length) { |
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
#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): |
OlderNewer