Skip to content

Instantly share code, notes, and snippets.

View codemilli's full-sized avatar
๐Ÿ˜‡
Hooked on React Hooks

codemilli codemilli

๐Ÿ˜‡
Hooked on React Hooks
View GitHub Profile
@codemilli
codemilli / gist:9db0c48f7d7fa0d18baa
Created January 23, 2016 01:29
how I write modules
My thoughts on writing tiny reusable modules that each do just one
thing. These notes were adapted from an email I recently sent.
***
If some component is reusable enough to be a module then the
maintenance gains are really worth the overhead of making a new
project with separate tests and docs. Splitting out a reusable
component might take 5 or 10 minutes to set up all the package
overhead but it's much easier to test and document a piece that is
import React from 'react';
class Test extends React.Component {
/**
* Test ์˜ ์ƒ์„ฑ์ž
* @constructs
* @param {Test.propTypes} props
*/
constructor(props) {
import React from 'react';
/**
* Define React Component $class$
*/
class $class$ extends React.Component {
/**
* Constructor for $class$
* @constructs
@codemilli
codemilli / network.java
Last active January 30, 2016 12:17
Get json data over network in Java
public JSONObject GET (String url) {
JSONObject json;
try {
URL target = new URL(url);
HttpURLConnection urlcon = (HttpURLConnection) target.openConnection();
InputStream in = new BufferedInputStream(urlcon.getInputStream());
BufferedReader streamReader = new BufferedReader(new InputStreamReader(in, "UTF-8"));
StringBuilder responseStrBuilder = new StringBuilder();
String inputStr;
while ((inputStr = streamReader.readLine()) != null)
@codemilli
codemilli / RestApi.java
Created January 30, 2016 12:26
Async Task with JSON Api request
private class RestApi extends AsyncTask<String, Void, JSONObject> {
@Override
protected JSONObject doInBackground(String... params) {
return this.GET(params[0]);
}
@Override
protected void onPostExecute(JSONObject jsonObject) {
super.onPostExecute(jsonObject);
this.onReceived(jsonObject);
// test1.js
var name = 'hckrmoon';
module.exports = name;
var isActive = $('body').hasClass('active');
if (isActive) {
$('p').show();
}
// Application ์˜ state ๋ฅผ View ์— ์ €์ •ํ•˜๊ณ  ์žˆ๋‹ค.
@codemilli
codemilli / deep-compare.js
Last active February 11, 2016 15:34
compare two object in javascript
const a = { blah: 1 };
const b = { blah: 1 };
const c = a;
const d = { blah: 2 };
const deepCompare = (obj1, obj2) => {
// ์ฒซ๋ฒˆ์งธ ์˜ค๋ธŒ์ ํŠธ์˜ ํ”„๋กœํผํ‹ฐ๋ฅผ ์ˆœํšŒํ•ฉ๋‹ˆ๋‹ค.
for (var p in obj1) {
// ๋‘ ์˜ค๋ธŒ์ ํŠธ ๋ชจ๋‘ ๊ฐ€์ง€๊ณ  ์žˆ์ง€ ์•Š๋Š” ํ”„๋กœํผํ‹ฐ์ด๋ฉด ๋‘ ์˜ค๋ธŒ์ ํŠธ๋Š” ๊ฐ™๋‹ค๊ณ  ํ•  ์ˆ˜ ์—†์Šต๋‹ˆ๋‹ค.
if (obj1.hasOwnProperty(p) !== obj2.hasOwnProperty(p)) return false;
@codemilli
codemilli / replaceNotEdit.js
Created February 11, 2016 16:48
The way of replacing an object not editing with ES6
/*
* Declare Object
*/
let profile = {
name: 'yunmi',
age: '26',
nickname: 'pinky'
};
/*
@codemilli
codemilli / purefunction.js
Created February 11, 2016 17:37
pure function ์„ ์ด์šฉํ•œ state ๊ฐ’ ๋Œ€์ฒด
var state = {
name: 'jooyoung Moon'
};
var reduce = function reduce(state) {
return _.extends({}, state, {
name: 'hckrmoon'
});
};