Skip to content

Instantly share code, notes, and snippets.

View fengt's full-sized avatar

Marco Feng fengt

  • team247
  • beijing
View GitHub Profile

Full socket.io client and server example

To see a full explanation, read my answer on SO here: https://stackoverflow.com/a/24232050/778272.

How to use

Create a folder, run npm init -f on it and paste both server.js and client.js there (see files below). Needless to say, you must have Node.js installed on your system.

Install the required libraries:

@fengt
fengt / jwtRS256.sh
Created November 4, 2019 11:00 — forked from ygotthilf/jwtRS256.sh
How to generate JWT RS256 key
ssh-keygen -t rsa -b 4096 -m PEM -f jwtRS256.key
# Don't add passphrase
openssl rsa -in jwtRS256.key -pubout -outform PEM -out jwtRS256.key.pub
cat jwtRS256.key
cat jwtRS256.key.pub
@fengt
fengt / CountryCodes.json
Created September 24, 2019 09:19 — forked from Goles/CountryCodes.json
Country and Dial or Phone codes in JSON format
[ { "name": "Afghanistan", "dial_code": "+93", "code": "AF" }, { "name": "Åland Islands", "dial_code": "+358", "code": "AX" }, { "name": "Albania", "dial_code": "+355", "code": "AL" }, { "name": "Algeria", "dial_code": "+213", "code": "DZ" }, { "name": "American Samoa", "dial_code": "+1684", "code": "AS" }, { "name": "Andorra", "dial_code": "+376", "code": "AD" }, { "name": "Angola", "dial_code": "+244", "code": "AO" }, { "name": "Anguilla", "dial_code": "+1264", "code": "AI" }, { "name": "Antarctica", "dial_code": "+672", "code": "AQ" }, { "name": "Antigua and Barbuda", "dial_code": "+1268", "code": "AG" }, { "name": "Argentina", "dial_code": "+54", "code": "AR" }, { "name": "Armenia", "dial_code": "+374", "code": "AM" }, { "name": "Aruba", "dial_code": "+297", "code": "AW" }, { "name": "Australia", "dial_code": "+61", "code": "AU" }, { "name": "Austria", "dial_code": "+43", "code": "AT" }, { "name": "Azerbaijan", "dial_code": "+994", "code": "AZ" }, { "name": "Bahamas", "dial_code": "+1242", "code": "BS" },
@fengt
fengt / sequelieze-field-encrypt.js
Created September 20, 2019 07:00 — forked from ajmas/sequelieze-field-encrypt.js
Code to encrypt a Sequelize fields
// Code to encrypt data in sequelize fields
// We are using ascii85 as a way save on storage. Also, note that
// the space delimiter we are using is a bit of an abuse since in
// normal cases ascii85 will skip over it, but since we are using
// after encoding and before encoding, it shouldn't be an issue.
//
// Fields are broken down to facilitate unit testing.
//
// based on code here: http://vancelucas.com/blog/stronger-encryption-and-decryption-in-node-js/
@fengt
fengt / encryption.js
Created September 20, 2019 06:59 — forked from vlucas/encryption.js
Stronger Encryption and Decryption in Node.js
'use strict';
const crypto = require('crypto');
const ENCRYPTION_KEY = process.env.ENCRYPTION_KEY; // Must be 256 bits (32 characters)
const IV_LENGTH = 16; // For AES, this is always 16
function encrypt(text) {
let iv = crypto.randomBytes(IV_LENGTH);
let cipher = crypto.createCipheriv('aes-256-cbc', Buffer.from(ENCRYPTION_KEY), iv);
@fengt
fengt / oracle_operate.md
Created January 23, 2018 08:45
This is common operation of oracle table.
  • alter column type:
alter table rfd_fms.worklog modify (content varchar2(400));
  • add column:
alter table rfd_fms.pixiu_codcheck add flag number(1) default 0 not null;
comment on column rfd_fms.pixiu_codcheck.flag is '标识, 0:妥投 1:全单';
@fengt
fengt / mysql_operate.md
Last active January 23, 2018 08:49
This is common operation of mysql table.
  • modify column type:
alter table formula_details modify val1 decimal(15,10);
  • change column name:
ALTER TABLE user CHANGE name newname CHAR(32) NOT NULL DEFAULT '123';
@fengt
fengt / emojis.json
Created January 15, 2018 02:26 — forked from oliveratgithub/emojis.json
Emoji-list with emojis, names, shortcodes, unicode and html entities [massive list]
{
"emojis": [
{"emoji": "👩‍👩‍👧‍👧", "name": "family_mothers_two_girls", "shortname": "", "unicode": "", "html": "👩‍👩‍👧‍👧", "category": "p", "order": ""},
{"emoji": "👩‍👩‍👧‍👦", "name": "family_mothers_children", "shortname": "", "unicode": "", "html": "👩‍👩‍👧‍👦", "category": "p", "order": ""},
{"emoji": "👩‍👩‍👦‍👦", "name": "family_mothers_two_boys", "shortname": "", "unicode": "", "html": "👩‍👩‍👦‍👦", "category": "p", "order": ""},
{"emoji": "👨‍👩‍👧‍👧", "name": "family_two_girls", "shortname": "", "unicode": "", "html": "👨‍👩‍👧‍👧", "category": "p", "order": ""},
{"emoji": "👨‍👩‍👧‍👦", "name": "family_children", "shortname": "", "unicode": "", "html": "👨‍👩‍👧‍👦", "category": "p", "order": ""},
{"emoji": "👨‍👩‍👦‍👦", "name": "family_two_boys", "shortname": "", "unicode": "", "html": "👨&zw
@fengt
fengt / dateConvert.md
Last active April 13, 2018 02:42
springBoot接收date类型参数转换

第一种方式(全局)

继承该类WebMvcConfigurerAdapter,注入如下bean:

@Bean
public Converter<String, Date> stringToDateConvert() {
  return new Converter<String, Date>() {
    @Override
    public Date convert(String source) {
      SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
      Date date = null;
@fengt
fengt / file_extension_verification.js
Created November 21, 2017 03:23
Upload file extension verification
$('#upload_btn').on('click', function() {
var uploadFile = $('#upload_categories').val();
if (!uploadFile) {
alertify.log('请先选择文件!', 'error', 0);
return;
}
var fileName = uploadFile.substr(uploadFile.lastIndexOf('\\')+1);
var ary = ['xls', 'xlsx'];
var suffix = uploadFile.split('.').pop().toLowerCase();