Skip to content

Instantly share code, notes, and snippets.

View wangshijun's full-sized avatar

wangshijun wangshijun

View GitHub Profile
@xjamundx
xjamundx / blog-webpack-2.md
Last active April 21, 2024 16:20
From Require.js to Webpack - Part 2 (the how)

This is the follow up to a post I wrote recently called From Require.js to Webpack - Party 1 (the why) which was published in my personal blog.

In that post I talked about 3 main reasons for moving from require.js to webpack:

  1. Common JS support
  2. NPM support
  3. a healthy loader/plugin ecosystem.

Here I'll instead talk about some of the technical challenges that we faced during the migration. Despite the clear benefits in developer experience (DX) the setup was fairly difficult and I'd like to cover some of the challanges we faced to make the transition a bit easier.

@ldong
ldong / download_egghead_videos.md
Last active December 7, 2023 16:16
download egghead videos

Download videos from egghead

Go to the egghead website, i.e. Building a React.js App

run

$.each($('h4 a'), function(index, video){
  console.log(video.href);
});
@wuhaixing
wuhaixing / views_in_keystone.md
Last active October 4, 2020 10:43
How to Construct Yourself UI in KeystoneJS

#How to Construct Yourself UI in KeystoneJS

KeystoneJS provide Admin UI with one set of route controllers and view templates(list&item) for all of the models.But usually,you will need some custome views other than Admin UI to display models. Although the KeystoneJS documention don't tell us much about how to contruct custome view,we can learn this from the source code in skeleton project generated by yo keystone,or you can just check out the keystone demo project's source code.We will walk through the blog feature's implementation in this demo application to demonstrate how to construct custome UI in KeystoneJS application.

As KeystoneJS documention described in Routes & Views section,there is a routes/index.js file, where we bind application's URL patterns to the controllers that load and process data, and render the appropriate template.You can find following code in it:

app.get('/blog/:catego

@JedWatson
JedWatson / API-Auth-With-KeystoneJS.md
Last active April 16, 2023 02:11
API Auth with KeystoneJS

To implement API authentication in KeystoneJS, you need the following:

For key based authentication

  • Middleware that validates the key in the request body or a header

For session based authentication

  • An endpoint that handles signin
  • An endpoint that handles signout
@shubhgo
shubhgo / README.md
Last active May 19, 2021 14:37
D3 tree with weighted links and color coding

A tree visualization built using d3 and inspired from mbostock's work. Some of the features supported are:

  • Weighted edges
  • Color coded links
  • Links originate along the height of the node instead of the center of the node

The MIT License (MIT)

Copyright (c) 2014 Shubham Goel

@kejun
kejun / gist:3f4851c7f3b3e209fcbb
Last active July 9, 2019 15:23
最近一次项目的总结

mathclub是最近做的一个个人项目,帮助考SAT的同学通过在线做题、回顾、问答提高成绩。用户功能有:计次/计时做题、成绩单、错题分布、错题回顾、提问、汇总以及注册登录。管理后台主要是题库管理、学员管理、成绩单管理、问题回复。怎么看都像学校里的课设,的确项目本身并不出奇,开发上选用的一些方案或许更有意思。

整个项目一个人从产品需求、原型设计、前后端开发到部署历时2周左右。可以从截图上感受一下:

image

技术选型上服务端是Node.js,应用框架选了老牌的Express(4.x变化挺大不少中间件都废了),数据服务用的是MongoLab(MongoDB的云服务平台),图片上传用的是又拍云,程序部署在Nodejitsu上。模板引擎没选主流的Jade或ejs,而是用Express React Views它实现了在服务端渲染React组件。前端框架是用React,这次有意想追求前后端全部组件化的组织。之前是用Webpack实现CommonJS模块打包,这次用Browserify配置更简单,它有丰富的transform很赞,其中的reactify转换React的JSX很完美。CSS用Sass+autoprefixer让人省心。将这一切串起来的自动构建工具是Gulp。我其实崇尚用最精简的工具组合开发,上述组合在我看来比较精简了。(帖纸留念)

![image](http://satexam.b0.upaiyu

@mscdex
mscdex / test.js
Last active September 15, 2023 11:55
sharing sessions between node.js and php using redis
var express = require('express'),
app = express(),
cookieParser = require('cookie-parser'),
session = require('express-session'),
RedisStore = require('connect-redis')(session);
app.use(express.static(__dirname + '/public'));
app.use(function(req, res, next) {
if (~req.url.indexOf('favicon'))
return res.send(404);
@addyosmani
addyosmani / browserify.md
Last active March 28, 2016 02:06
Yeoman + Browserify

Yeoman generators with Browserify

Browserify is a tool that allows us to write node-style modules that compile for use in the browser. Like node, we write our modules in separate files, exporting external methods and properties using the module.exports and exports variables

generator-browserify is a generator with a Browserify setup, offering choices between Gulp or Grunt and Foundation or Bootstrap.

screenshot 2014-04-20 at 10 19 09 pm

generator-angular-with-browserify is a generator for bundling Angular.js with Browserify

//Practically all this code comes from https://github.com/alangrafu/radar-chart-d3
//I only made some additions and aesthetic adjustments to make the chart look better
//(of course, that is only my point of view)
//Such as a better placement of the titles at each line end,
//adding numbers that reflect what each circular level stands for
//Not placing the last level and slight differences in color
//
//For a bit of extra information check the blog about it:
//http://nbremer.blogspot.nl/2013/09/making-d3-radar-chart-look-bit-better.html
@rojan
rojan / node_crypto.js
Last active March 19, 2023 15:14
Encrypt in nodejs and decrypt in php or vice versa
var crypto = require('crypto');
var key = 'MySecretKey12345';
var iv = '1234567890123456';
var cipher = crypto.createCipheriv('aes-128-cbc', key, iv);
var decipher = crypto.createDecipheriv('aes-128-cbc', key, iv);
var text = 'plain text';
var encrypted = cipher.update(text, 'utf8', 'binary');
encrypted += cipher.final('binary');
hexVal = new Buffer(encrypted, 'binary');