Skip to content

Instantly share code, notes, and snippets.

@bitgord
bitgord / Quick-ES6-Setup
Created December 11, 2016 21:27
Quick setup of a ES6 environment with nodemon and babel
// First you need to have node version 5 or newer
// Create a new project folder with a package.json file
mkdir [[new project name]]
cd [[new project name]]
npm init
// Install babel
npm install babel-preset-es2015
@sanhuang
sanhuang / README.md
Created November 29, 2016 07:25
繁簡體中文日文韓文的Unicode字元範圍

** 匹配Unicode字符的正則表達式

這裡是幾個主要非英文語系字符範圍(google上找到的):

  • 2E80~33FFh:中日韓符號區。收容康熙字典部首、中日韓輔助部首、注音符號、日本假名、韓文音符,中日韓的符號、標點、帶圈或帶括符文數字、月份,以及日本的假名組合、單位、年號、月份、日期、時間等。
  • 3400~4DFFh:中日韓認同表意文字擴充A區,總計收容6,582個中日韓漢字。
  • 4E00~9FFFh:中日韓認同表意文字區,總計收容20,902個中日韓漢字。
  • A000~A4FFh:彝族文字區,收容中國南方彝族文字和字根。
  • AC00~D7FFh:韓文拼音組合字區,收容以韓文音符拼成的文字。
  • F900~FAFFh:中日韓兼容表意文字區,總計收容302個中日韓漢字。
  • FB00~FFFDh:文字表現形式區,收容組合拉丁文字、希伯來文、阿拉伯文、中日韓直式標點、小符號、半角符號、全角符號等。
@sam-artuso
sam-artuso / setting-up-babel-nodemon.md
Last active November 3, 2023 08:52
Setting up Babel and nodemon

Setting up Babel and nodemon

Inital set-up

Set up project:

mkdir project
cd project
npm init -y
@robinmonjo
robinmonjo / es6-higher-order-component.md
Last active March 14, 2019 17:27
ES6 Higher Order Components

Redux higher order components

Sometimes we need to share props and behaviour between multiple components/containers. For that we can do a higher order component. Example:

Decorator component

Higher Order Component that will decorate other component:

@hartzis
hartzis / Image.jsx
Last active October 4, 2018 06:57
React Universal/Isomorphic Image onError Component
class Image extends Component {
componentDidMount() {
// if image hasn't completed loading, then let react handle error
if (!this._image.complete) return;
// if image has finished loading and has 'errored'(errored when naturalWidth === 0)
// then run the onError callback
if (this._image.naturalWidth === 0) {
this.props.onError();
}
}
#!/bin/bash
cd /tmp
file=$(date +%a).sql
mysqldump \
--host ${MYSQL_HOST} \
--port ${MYSQL_PORT} \
-u ${MYSQL_USER} \
--password="${MYSQL_PASS}" \
${MYSQL_DB} > ${file}
if [ "${?}" -eq 0 ]; then
@carloscarucce
carloscarucce / pagination.blade.php
Last active January 27, 2023 03:10
Pagination template for laravel 5
@if (isset($paginator) && $paginator->lastPage() > 1)
<ul class="pagination">
<?php
$interval = isset($interval) ? abs(intval($interval)) : 3 ;
$from = $paginator->currentPage() - $interval;
if($from < 1){
$from = 1;
}
@xabikos
xabikos / remote react bootstrap table example
Last active July 8, 2021 00:16
An example of a react bootstrap table that fetches the data asynchronously when navigating between pages and when changing the page size
import React, {Component} from 'react';
import {BootstrapTable, TableHeaderColumn} from 'react-bootstrap-table';
import _ from 'lodash';
const dataTable = _.range(1, 60).map(x => ({id: x, name: `Name ${x}`, surname: `Surname ${x}`}));
// Simulates the call to the server to get the data
const fakeDataFetcher = {
fetch(page, size) {
return new Promise((resolve, reject) => {
module.exports = {
up: function (queryInterface, Sequelize) {
return [
queryInterface.addColumn('User', 'name', {
type: Sequelize.STRING
}),
queryInterface.addColumn('User', 'nickname', {
type: Sequelize.STRING,
})
];
@caojianhua
caojianhua / ImageToCVPixelBuffer.m
Last active June 10, 2017 20:48
Create CVPixelBufferRef from an UIImage
+ (CVPixelBufferRef)pixelBufferFromImage:(UIImage *)image {
NSData * rawImageData = [UIImage RawRepresentation:image pixelFormat:SVPixelFormat_BGRA];
NSDictionary * attributes = @{
(NSString *)kCVPixelBufferIOSurfacePropertiesKey : @{},
(NSString *)kCVPixelBufferCGImageCompatibilityKey : @(YES),
(NSString *)kCVPixelBufferOpenGLESCompatibilityKey : @(YES),
(NSString *)kCVPixelBufferCGBitmapContextCompatibilityKey : @(YES),
};