Skip to content

Instantly share code, notes, and snippets.

@thanhsmind
thanhsmind / tai-file-bi-chan-download-tu-google-drive
Created May 4, 2023 07:13 — forked from hauvuhd/tai-file-bi-chan-download-tu-google-drive
Tải file bị chặn download từ Google Drive - PDF
let jspdf = document.createElement("script");
jspdf.onload = function () {
let pdf = new jsPDF();
let elements = document.getElementsByTagName("img");
for (let i in elements) {
let img = elements[i];
if (!/^blob:/.test(img.src)) {
continue;
@thanhsmind
thanhsmind / django_permission_required.txt
Last active March 2, 2019 03:48
Django: Easy use permission on View with Decorator
# views.py
# Use decorator require permission on Django
from django.contrib.auth.decorators import permission_required
@permission_required('product.manage_products')
def product_list(request):
pass
@thanhsmind
thanhsmind / django_permission_system
Created February 20, 2019 07:24
How to use Django permission System?
from django.test import TestCase
from django.contrib.auth.models import User, Group, Permission
from django.contrib.contenttypes.models import ContentType
from django.contrib.auth import get_user_model
# Create your tests here.
class DjangoGroupPermissionTests(TestCase):
def setUp(self):
@thanhsmind
thanhsmind / gist:bc51a292a8abc558fbda083d5b19e7eb
Created July 30, 2018 04:50
Start project reactjs & redux from scratch
# Init project Reactjs
$ mkdir project-name
$ cd project-name
# create file package.json
$ npm init
# install webpack
$ npm install --save webpack
# Symbol
@thanhsmind
thanhsmind / higher-oder-functiton-ex2.js
Created July 23, 2018 06:52
Higher-Order Functions in React
export const doIncrement = state =>
({ counter: state.counter + 1 });
export const doDecrement = state =>
({ counter: state.counter - 1 });
class Counter extends Component {
state = {
counter: 0,
};
@thanhsmind
thanhsmind / higher-oder-functiton-ex1.js
Created July 23, 2018 06:51
Higher-Order Functions in React
// Source:https://www.robinwieruch.de/javascript-fundamentals-react-requirements/
import React, { Component } from 'react';
// function doFilter(query) {
// return function (user) {
// return query === user.name;
// }
// }
const doFilter = query => user =>
@thanhsmind
thanhsmind / arrow-function-ex2.js
Created July 22, 2018 08:29
arrow function example 2
// Khi không sử dụng Arrow Function
// this.age++; sẽ hiểu this = global chứ không phải là this.age trong Object Person
function Person() {
// The Person() constructor defines `this` as an instance of itself.
this.age = 0;
setInterval(function growUp() {
// In non-strict mode, the growUp() function defines `this`
// as the global object (because it's where growUp() is executed.),
// which is different from the `this`
@thanhsmind
thanhsmind / arrow-function-ex1.js
Created July 22, 2018 08:25
Arrow Function example 1
// Source: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/Arrow_functions
var elements = [
'Hydrogen',
'Helium',
'Lithium',
'Beryllium'
];
elements.map(function(element ) {
return element.length;
// source: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/Arrow_functions
// Basic Syntax
(param1, param2, …, paramN) => { statements }
(param1, param2, …, paramN) => expression
// equivalent to: => { return expression; }
// Parentheses are optional when there's only one parameter name:
(singleParam) => { statements }
singleParam => { statements }
@thanhsmind
thanhsmind / gist:a1fefc49fd2607de38ee1277bde0eafa
Last active July 18, 2018 10:23
super function on react component
/**
* In React, when you call super with props.
* React will make props available across the component through this.props.
* This allows us to call this.props.websites when the data is on the parent component.
*/
class App extends Component {
constructor(props) {
super(props);
this.state = { websites: [] };
}