Skip to content

Instantly share code, notes, and snippets.

View WillieYang's full-sized avatar
🎧
Focusing

Willie Yang WillieYang

🎧
Focusing
View GitHub Profile
@WillieYang
WillieYang / configure.js
Last active September 8, 2017 10:49
Using GCP to create a shadowsocks server
// server side setting about shadowsocks
{
"server":"0.0.0.0",
"server_port":8838,
"local_address":"127.0.0.1",
"local_port":1080,
"password":"ys123456",
"timeout":600,
"method":"aes-256-cfb"
}
@WillieYang
WillieYang / static_map_error.js
Created August 9, 2017 16:39
map error: g.co/staticmaperror
// Change the bug when the list loation is not in the databse,
// the post data of lat and lng are undefined, actually, we need
// to convert the data structure from the array to a javascript object
//(lag: and lng: in coords rather than coords[0] and coords[1]
body_post.coords = {
lng: body_post.coords[0],
lat: body_post.coords[1]
};
@WillieYang
WillieYang / command.js
Created August 6, 2017 11:06
ubuntu 16.04 disable touchpad when mouse plugged in
// command line below to enable this requirements
gsettings set org.gnome.desktop.peripherals.touchpad send-events disabled-on-external-mouse
// get current situation
gsettings get org.gnome.desktop.peripherals.touchpad send-events
// options
@WillieYang
WillieYang / mode_register_error.js
Last active August 3, 2017 10:18
MongooseError: Schema hasn't been registered for model "Report"
// need to require the reports.js(schema file in model) in db connect file
[nodemon] restarting due to changes...
[nodemon] starting `node ./bin/www`
(node:26035) MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 exit listeners added. Use emitter.setMaxListeners() to increase limit
/home/sheng/Work/smr_pjt_loct_dr/node_modules/mongoose/lib/index.js:382
throw new mongoose.Error.MissingSchemaError(name);
^
MongooseError: Schema hasn't been registered for model "Report".
@WillieYang
WillieYang / subdocument_find.js
Created July 29, 2017 16:31
How to find a particular subdocument in a document by condition?
// example when using _id as a query condition
// need to utilize the $element and $ (Positional projection)
> db.users.find({"_id": ObjectId("5974c986dea685349a68242a"), 'userLocation': {"$elemMatch": {'locationName': "Uni Kebab"}}}, {"userLocation.$": 1}).pretty();
{
"_id" : ObjectId("5974c986dea685349a68242a"),
"userLocation" : [
{
"locationName" : "Uni Kebab",
"locationAddress" : "190 Burgess Road, Southampton",
@WillieYang
WillieYang / passprot_cannot_find_err.js
Created July 24, 2017 10:08
when deploying the latest version to the heroku, it says that passport cannot find...
2017-07-23T23:24:22.178525+00:00 app[web.1]: module.js:472
2017-07-23T23:24:22.178541+00:00 app[web.1]: throw err;
2017-07-23T23:24:22.178542+00:00 app[web.1]:
2017-07-23T23:24:22.178544+00:00 app[web.1]: at Function.Module._resolveFilename (module.js:470:15)
2017-07-23T23:24:22.178545+00:00 app[web.1]: at Function.Module._load (module.js:418:25)
2017-07-23T23:24:22.178545+00:00 app[web.1]: at Module.require (module.js:498:17)
2017-07-23T23:24:22.178542+00:00 app[web.1]: ^
2017-07-23T23:24:22.178546+00:00 app[web.1]: at require (internal/module.js:20:19)
2017-07-23T23:24:22.178543+00:00 app[web.1]: Error: Cannot find module 'passport'
2017-07-23T23:24:22.178547+00:00 app[web.1]: at Module._compile (module.js:571:32)
@WillieYang
WillieYang / relative_path.js
Created July 22, 2017 16:40
what is the difference between / and ./ and ../ in relative path?
/
means the root of the current drive;
./
means the current directory;
../
means the parent of the current directory.
@WillieYang
WillieYang / uses.js
Created July 22, 2017 16:19
what is the method: mongoose.model();
// Require the Mongoose
var mongoose = require('mongoose');
// Schema for user
var UserSchema = new mongoose.Schema({
username: {type: String, required: true},
email: {type: String, unique: true, required: true},
password: {type: String, required: true},
});
@WillieYang
WillieYang / bug_html5_geolocation.js
Created July 22, 2017 09:09
Bugs about HTML5 Geolocation
// OS: ubuntu 16.04 LTS
// Every time in the evening after 9 pm, the HTML5 GeoLocation API in Chromium and Firefox would not work.
// Is is a bug or something?
@WillieYang
WillieYang / req.query.js
Created July 19, 2017 10:07
HTTP notation of types
Check the type of location:string
get the query location:15
location type: "[object Object]"
name:undefined
location id:ChIJ2WK8mvNzdEgRyilaQFDCp1M
// HTTP has no notation of types, everything is a string, as for req.query, it cannot pass the JavaScript Object, only string
// even as for integers.