Skip to content

Instantly share code, notes, and snippets.

@huangzhuolin
huangzhuolin / deploy-create-react-app-with-nginx.md
Last active October 9, 2024 19:52
[Deploy create-react-app(react-router) with nginx] #react #nginx

Create-react-app

Create React apps with no build configuration.

Thanks to create-react-app. It's saves a lot of my time. I remember several months ago I had to setup a lot just for a react app, webpack, babel, test environment and so on... Fortunately, everything becomes easy now. Though you have many choices of start boiler plate, you worth trying this.

React router

If you are build a SPA with react, you probably use react-router.

@huangzhuolin
huangzhuolin / panel_ctrl.ts
Last active June 7, 2018 05:15
[grafana panel add/remove tag dynamically] fix: when dynamically remove and add tag, tab template and directive is not updated correctly #grafana #angularjs
// ...
export class PanelCtrl {
// ...
addEditorTab(title, directiveFn, index?) {
let editorTab = { title, directiveFn };
if (_.isString(directiveFn)) {
editorTab.directiveFn = function() {
return { templateUrl: directiveFn };
@huangzhuolin
huangzhuolin / my-controller.js
Created June 7, 2018 05:28
[access search parameters(or $routeParams) in controller with `$inject`] #angularjs
constructor($scope, $injector) {
this.$injector = $injector;
this.$scope = $scope;
// ...
// access url params
someFunc(){
const routeParams = this.$injector.get("$routeParams");
const searchParams = this.$injector.get("$location").search();
// ...
@huangzhuolin
huangzhuolin / create-django-modal-diagram.sh
Created June 15, 2018 09:35
[Generate (and view) a graphviz graph of app models] #mac #python #django
# mac os
brew install graphviz
pip install pygraphviz
pip install django-extensions
python manage.py graph_models trees -o test.png
@huangzhuolin
huangzhuolin / python-iterable-and-iterator.md
Last active June 20, 2018 08:49
[python iterable, iterator and generator function] #python

differences between iterables and iterators

iterables have an __iter__ method that instantiates a new iterator every time. iterators implement a __next__ method that returns individual items, and an __iter__ method that returns self.

Therefore, iterators are also iterable, but iterables are not iterators.

generator function

@huangzhuolin
huangzhuolin / flags.py
Created June 28, 2018 12:51
[downloading with concurrent.futures] web downloads in three styles #python
# sequential download script
import os
import time
import sys
import requests
POP20_CC = ('CN IN US ID BR PK NG BD RU JP '
'MX PH VN ET EG DE IR TR CD FR').split()
@huangzhuolin
huangzhuolin / angularjs-directives.md
Last active July 3, 2018 08:53
[angularjs directives] #angularjs

Directives

refs

https://docs.angularjs.org/guide/directive

Definition

At a high level, directives are markers on a DOM element (such as an attribute, element name, comment or CSS class) that tell AngularJS's HTML compiler ($compile) to attach a specified behavior to that DOM element (e.g. via event listeners), or even to transform the DOM element and its children.

matching directives

  1. `` element matches the ngModel directive
@huangzhuolin
huangzhuolin / componentCtrl.js
Created August 2, 2018 10:11
[pass function as parameter to component in anglularjs] #angularjs
// ...
export class ComponentCtrl {
// ...
onClick() {
// We can access outer scope function here with the binding name.
this.outerHandleClick({param1: 1, param2: 2}) // We can also pass parameters to outer function.
}
}
@huangzhuolin
huangzhuolin / index.md
Last active August 30, 2018 02:58
[implement dashboard like grafana using highstock] #react #highcharts

In grafana, when we click in the chart and drag, we can select the time range to display. The effect will be propagated to the whole dashboard, and every panel will be set to the specific time range.

Now we try to realize the same effect using React and Highcharts.

  1. The highchart's option to enable the function that we can drag to select time range is below.
{
  chart: { zoomType: 'x' }
}
@huangzhuolin
huangzhuolin / index.sql
Created September 14, 2018 02:53
[mysql select case when] #mysql
select case field_a
when '1' then 'cat'
when '2' then 'dog'
else 'unknown'
end
from my_table;