Skip to content

Instantly share code, notes, and snippets.

@dongcai
dongcai / react-plus.jsx
Last active August 3, 2018 15:34
Standalone react to render two component with one ReactDOM.render()
const topics = ["php", "jquery", "reactjs"];
class RedditFeed extends React.Component {
render() {
return (
<ul>
{this.props.posts.map(post => (
<li key={post.id}>
<a href={post.url} target="_blank">
{post.title}
@dongcai
dongcai / react.jsx
Created August 1, 2018 18:36
Every request only updates the data source, and the ReactJS does the rest
const topics = ["php", "jquery", "reactjs"];
class RedditFeed extends React.Component {
render() {
return (
<div>
<ul>
{this.props.posts.map(post => (
<li key={post.id}>
<a href={post.url} target="_blank">
@dongcai
dongcai / jquery.js
Created August 1, 2018 18:32
Every request only updates what it needs to be updated
function getRedditFeed() {
var topic = $('#select-topic').val();
$.getJSON("https://www.reddit.com/r/" + topic + ".json", function(data) {
$.each(data.data.children, function(i, item) {
$('<li><a href="' + item.data.url + '" target="_blank">' + item.data.title + '</a></li>').appendTo("#posts");
});
});
}
$(document).ready(function() {
@dongcai
dongcai / reload.php
Created August 1, 2018 18:29
Every request causes the page to reload
<div id="root">
<ul>
<?php
$topic = isset( $_GET['topic'] ) ? trim( $_GET['topic'] ) : "php";
$reddit_url = "https://www.reddit.com/r/" . urlencode( $topic ) . ".json";
$result = file_get_contents( $reddit_url );
$result_arr = json_decode( $result, TRUE );
$data = isset( $result_arr['data'] ) ?
$result_arr['data']['children']: NULL;
@dongcai
dongcai / nginx-tuning.md
Created June 29, 2018 13:29 — forked from denji/nginx-tuning.md
NGINX tuning for best performance

Moved to git repository: https://github.com/denji/nginx-tuning

NGINX Tuning For Best Performance

For this configuration you can use web server you like, i decided, because i work mostly with it to use nginx.

Generally, properly configured nginx can handle up to 400K to 500K requests per second (clustered), most what i saw is 50K to 80K (non-clustered) requests per second and 30% CPU load, course, this was 2 x Intel Xeon with HyperThreading enabled, but it can work without problem on slower machines.

You must understand that this config is used in testing environment and not in production so you will need to find a way to implement most of those features best possible for your servers.