In Javascript this is bound in unexpected ways. Functions, in particular, create a new 'this' and so when you want to keep a reference to an "outer" object you sometimes see the pattern:
var self = this;
as in:
var self = this;| # Created by .ignore support plugin (hsz.mobi) | |
| ### Python template | |
| # Byte-compiled / optimized / DLL files | |
| __pycache__/ | |
| *.py[cod] | |
| *$py.class | |
| # C extensions | |
| *.so |
| #!/bin/sh | |
| # Make sure to: | |
| # 1) Name this file `backup.sh` and place it in /home/ubuntu | |
| # 2) Run sudo apt-get install awscli to install the AWSCLI | |
| # 3) Run aws configure (enter s3-authorized IAM user and specify region) | |
| # 4) Fill in DB host + name | |
| # 5) Create S3 bucket for the backups and fill it in below (set a lifecycle rule to expire files older than X days in the bucket) | |
| # 6) Run chmod +x backup.sh | |
| # 7) Test it out via ./backup.sh |
| /* | |
| ##Device = Desktops | |
| ##Screen = 1281px to higher resolution desktops | |
| */ | |
| @media (min-width: 1281px) { | |
| /* CSS */ | |
| /** | |
| * This code is licensed under the terms of the MIT license | |
| * | |
| * Deep diff between two object, using lodash | |
| * @param {Object} object Object compared | |
| * @param {Object} base Object to compare with | |
| * @return {Object} Return a new object who represent the diff | |
| */ | |
| function difference(object, base) { | |
| function changes(object, base) { |
| class Foo { | |
| constructor(x,y,z) { | |
| Object.assign(this,{ x, y, z }); | |
| } | |
| hello() { | |
| console.log(this.x + this.y + this.z); | |
| } | |
| } |
| // https://codepen.io/hartzis/pen/VvNGZP | |
| class ImageUpload extends Component { | |
| constructor(props) { | |
| super(props); | |
| this.state = { | |
| file: '', | |
| imagePreviewUrl: '' | |
| }; | |
| this._handleImageChange = this._handleImageChange.bind(this); | |
| this._handleSubmit = this._handleSubmit.bind(this); |
| //equivalent of MySQL SELECT COUNT(*) AS cnt, fieldName FROM someTable GROUP BY fieldName; | |
| db.someCollection.aggregate([{"$group" : {_id:"$fieldName", cnt:{$sum:1}}}]); | |
| //as above but ordered by the count descending | |
| //eg: SELECT COUNT(*) AS cnt, fieldName FROM someTable GROUP BY fieldName ORDER BY cnt DESC; | |
| db.someCollection.aggregate([{"$group" : {_id:"$fieldName", cnt:{$sum:1}}}, {$sort:{'cnt':-1}}]); |
| # AWS Version 4 signing example | |
| # taken from: | |
| # http://docs.aws.amazon.com/general/latest/gr/sigv4-signed-request-examples.html | |
| # Lambda API (InvokeAsync) | |
| # http://docs.aws.amazon.com/lambda/latest/dg/API_InvokeAsync.html | |
| # See: http://docs.aws.amazon.com/general/latest/gr/sigv4_signing.html | |
| # This version makes a POST request and passes request parameters | |
| # in the body (payload) of the request. Auth information is passed in |
| import Foundation | |
| // MARK: - Comparable | |
| extension NSDecimalNumber: Comparable {} | |
| public func ==(lhs: NSDecimalNumber, rhs: NSDecimalNumber) -> Bool { | |
| return lhs.compare(rhs) == .OrderedSame | |
| } |