Skip to content

Instantly share code, notes, and snippets.

View srph's full-sized avatar
🛠️
Building @Stride-Labs Frontend

Kier Borromeo srph

🛠️
Building @Stride-Labs Frontend
View GitHub Profile
@srph
srph / array_find_index.php
Created March 17, 2017 22:46
PHP: array_find_index
<?php
function array_find_index(array $array, Closure $callback) {
for ($i = 0; $i < count($array); $i++) {
if ($callback($array[$i], $i)) {
return $i;
}
}
return -1;
@srph
srph / auth.js
Created February 14, 2017 19:54
react: permissions
import React from 'react';
import store from 'app/store';
import history from 'app/history';
/**
* Make page accessibly only by logged in users
* @TODO: Redirect to page originally being visited by user.
*/
export default function auth(Component) {
return class AuthPermissionComponent extends React.Component {
@srph
srph / index.js
Created February 10, 2017 09:48
JS: Sort ascending, but sort invalid ones (0 in this case) to the end
[0,5,8,1,3,1,6].sort((a, b) => a === 0 ? true : a > b);
// // [1, 1, 3, 5, 6, 8, 0]
@srph
srph / index.html
Created February 3, 2017 17:38 — forked from dreyescat/index.html
Webpack config to expose bundle in a variable in the global context
<html>
<head>
</head>
<body>
<script src="lib/yourlib.js"></script>
<script>
window.onload = function () {
EntryPoint.run();
};
</script>
@srph
srph / Nbsp.js
Created February 3, 2017 07:36
React: html entity component. Because Buble won't let me use html entities
import React from 'react';
const Entity = ({char}) =>
<span dangerouslySetInnerHTML={{ __html: `&${char};` }} />
Entity.propTypes = {
char: React.PropTypes.string.isRequired
};
export default Entity;
import React, {Component, PropTypes} from 'react';
import axios from 'axios';
import omit from 'lodash/omit';
export default class DynamicSelect extends Component {
constructor(props) {
super(props);
this.state = {
loading: false,
@srph
srph / serialize.js
Created January 18, 2017 05:09
jQuery: Transform serialized form data into POJO
/**
* Transform serialized form data to POJO
* @param {jQuery}
* @return {object}
*/
function serialize(form) {
return form.serializeArray().reduce(function(previous, next) {
previous[next.name] = next.value || '';
return previous;
}, {});
@srph
srph / index.js
Created January 12, 2017 15:27
JS: Group By
module.exports = function groupBy(arr, fn) {
var group = {};
arr.forEach(function(v, k) {
var prop = group[fn(v, k)];
prop == null ? prop = [v] : prop.push(v);
});
return group;
}
@srph
srph / throttle.js
Last active December 20, 2016 14:09
JS: Throttle
function throttle(cb, ms) {
var flag = false;
return function() {
var context = this;
var args = arguments;
if ( flag ) {
return;
}
@srph
srph / readme.md
Last active November 23, 2016 02:34
Reasonable, Loose Development Process

Reasonable, Loose Development Process

Note that in this process, we’re not trying to ship half-assed products. This isn’t a 24-hour hackathon. But of course, we’re also trying to ship products as soon as possible while considering everybody’s efficiency and interests and the business's market and users.

We will try to avoid dependency as much as possible.

This doesn’t have to be strictly followed. This only allows the team to have a general guideline in their process so everybody understands what they’re supposed to do, how they’re supposed to do, and for how long. Tweak it to your team's work speed and project's difficulty.

Some products can also be hard. But of course, most products take more time than needed because of the noise; everything that’s not necessarily the main functionality but important: auth, etc.