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 / 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() {
@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) {
var myObjArray = [
{
name: 'peter',
age: 25
},
{
name: 'john',
age: 15
@freewayz
freewayz / frontendDevlopmentBookmarks.md
Created October 7, 2016 04:45 — forked from dypsilon/frontendDevlopmentBookmarks.md
A badass list of frontend development resources I collected over time.
@freewayz
freewayz / capitalize-obj.js
Created October 11, 2016 12:43
Iterating over array of object and capitailizing the first leter
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)) {
@freewayz
freewayz / capitalize-obj.js
Created October 11, 2016 12:43
Iterating over array of object and capitailizing the first leter
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)) {
@freewayz
freewayz / flatten_array.py
Created February 12, 2017 23:59
Python implementation of flatten an array
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