Skip to content

Instantly share code, notes, and snippets.

Avatar
🎯
Focusing

dushujun

🎯
Focusing
View GitHub Profile
@dushujun
dushujun / 0_reuse_code.js
Created Apr 24, 2016
Here are some things you can do with Gists in GistBox.
View 0_reuse_code.js
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@dushujun
dushujun / auth.markdown
Created Aug 19, 2016 — forked from mlynch/auth.markdown
AngularJS Authentication and CORS
View auth.markdown

Single Page Apps are ruling the world and AngularJS is leading the charge. But many of the lessons we learned in the Web 2.0 era no longer apply, and few are as drastically different as authentication.

CORS

CORS is an oft-misunderstood feature of new browsers that is configured by a remote server. CORS stands for Cross-Origin-Resource-Sharing, and was designed to make it possible to access services outside of the current origin (or domain) of the current page.

Like many browser features, CORS works because we all agree that it works. So all major browsers like Chrome, Firefox, and IE support and enforce it. By using these browsers, you benefit from the security of CORS.

That means certain browsers do not enforce it, so it is not relevant there. One large example is a native Web View for things like Cordova and Phonegap. However, these tools often have configuration options for whitelisting domains so you can add some security that way.

@dushujun
dushujun / ID.js
Created Aug 24, 2016 — forked from gordonbrander/ID.js
ID - a unique ID/name generator for JavaScript
View ID.js
// Generate unique IDs for use as pseudo-private/protected names.
// Similar in concept to
// <http://wiki.ecmascript.org/doku.php?id=strawman:names>.
//
// The goals of this function are twofold:
//
// * Provide a way to generate a string guaranteed to be unique when compared
// to other strings generated by this function.
// * Make the string complex enough that it is highly unlikely to be
// accidentally duplicated by hand (this is key if you're using `ID`
@dushujun
dushujun / README.md
Created Sep 26, 2016 — forked from addyosmani/README.md
108 byte CSS Layout Debugger
View README.md

CSS Layout Debugger

A tweet-sized debugger for visualizing your CSS layouts. Outlines every DOM element on your page a random (valid) CSS hex color.

One-line version to paste in your DevTools

Use $$ if your browser aliases it:

~ 108 byte version

View str2unicode.py
def str2unicode(data):
"""从bt拿到的任务参数是str, 需要转换成unicode"""
if isinstance(data, str):
return data.decode('utf8')
elif isinstance(data, unicode):
return data
elif isinstance(data, collections.Mapping):
return dict(map(str2unicode, data.iteritems()))
elif isinstance(data, collections.Iterable):
return type(data)(map(str2unicode, data))
@dushujun
dushujun / es_query_by_string_length.json
Created May 4, 2017
elasticsearch query by string length
View es_query_by_string_length.json
{
"query": {
"bool": {
"must": {
"script": {
"script": {
"inline": "doc['被执行人姓名/名称.raw'].getValue().length() < 4 ",
"lang": "painless"
}
}
@dushujun
dushujun / introrx.md
Created Jul 20, 2017 — forked from staltz/introrx.md
The introduction to Reactive Programming you've been missing
View introrx.md
View playground.rs
macro_rules! enum_with_str_representation {
(enum $enum_name:ident {
$($variant:ident => $nice_name:expr,)+
}) => {
#[derive(Debug, PartialEq, Eq, Clone, Hash)]
enum $enum_name {
$($variant),+
}
impl ::std::fmt::Display for $enum_name {
@dushujun
dushujun / readme.md
Created Oct 23, 2017 — forked from paulirish/readme.md
resolving the proper location and line number through a console.log wrapper
View readme.md

console.log wrap resolving for your wrapped console logs

I've heard this before:

What I really get frustrated by is that I cannot wrap console.* and preserve line numbers

We enabled this in Chrome DevTools via blackboxing a bit ago.

If you blackbox the script file the contains the console log wrapper, the script location shown in the console will be corrected to the original source file and line number. Click, and the full source is looking longingly into your eyes.

View keybase.md

Keybase proof

I hereby claim:

  • I am dushujun on github.
  • I am shujun (https://keybase.io/shujun) on keybase.
  • I have a public key ASDvp0WQVChQYr6fDay77M7gFMuHvHpKkDegXLkuKwc58go

To claim this, I am signing this object:

You can’t perform that action at this time.