Skip to content

Instantly share code, notes, and snippets.

View freewayz's full-sized avatar
🏠
Working from home

Peter Edache freewayz

🏠
Working from home
View GitHub Profile
//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)]
@freewayz
freewayz / simple-oop.js
Created January 4, 2016 18:43
Simple OOP concept in javascript
//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);
@freewayz
freewayz / json-object-js-object.js
Created January 4, 2016 18:51
Passing json to object in javascript object
/*
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"};
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
@freewayz
freewayz / Hello.js
Last active January 26, 2016 12:02
React ES6 component creation
class App extends React.Component {
static propTypes = {
params: PropTypes.object.isRequired,
};
state = {
....
};
componentWillMount() {
var myObjArray = [
{
name: 'peter',
age: 25
},
{
name: 'john',
age: 15
@freewayz
freewayz / RandomURLKeyGenerator.java
Created July 21, 2016 11:03
How to generate a secure random safe URL in Java, using apache libary
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) {
@freewayz
freewayz / boto-s3-upload-directory.py
Created August 12, 2016 10:35
How to use python and amazon boto to upload the Amazon s3
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)
@freewayz
freewayz / django_model_deletable.py
Created September 27, 2016 14:43
Django check if model has related object before Deleting the model
#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)
@freewayz
freewayz / aws-boto-s3-download-directory.py
Created October 6, 2016 15:35
Download files and folder from amazon s3 using boto and pytho local system
#!/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):