Skip to content

Instantly share code, notes, and snippets.

Put a closure on it

Sometimes you'll have objects that manage state along with event handling. This happens frequently in MVC apps. Let's start with a messy example:

var Launcher = function(rocket) {
  this.rocket = rocket
}

Launcher.prototype.isReady = function() {

From the chat:
Vijay Velagapudi 12:16 PM
no problem
To list all available commands enter "/?".
John Elliott 12:23 PM
https://dl.dropboxusercontent.com/u/23241016/startup%20engineering%20public/Lecture-all.pdf - Lecture Notes in one file on Dropbox
Nghia Hoang 12:23 PM
http://www.html5rocks.com/en/tutorials/es7/observe/
http://ng-learn.org/2014/03/AngularJS-2-Status-Preview/
http://eisenbergeffect.bluespire.com/all-about-angular-2-0/
http://www.w3.org/wiki/WebComponents/
https://docs.google.com/document/d/11YUzC-1d0V1-Q3V0fQ7KSit97HnZoKVygDxpWzEYW0U/edit
https://speakerdeck.com/rauschma/ecmascript-6-whats-next-for-javascript-august-2014
http://pascalprecht.github.io/2014/10/25/integrating-web-components-with-angularjs/
https://docs.google.com/document/d/1kpuR512G1b0D8egl9245OHaG0cFh0ST0ekhD_g8sxtI/edit#heading=h.xgjl2srtytjt
https://docs.google.com/presentation/d/1Gv-dvU-yy6WY7SiNJ9QRo9XayPS6N2jtgWezdRpoI04/present?slide=id.g108668b30_040
http://code.tutsplus.com/tutorials/using-polymer-to-create-web-components--cms-20475
// AtScript
import {Component} from 'angular';
import {Server} from './server';
@Component({selector: 'foo'})
export class MyComponent {
constructor(server:Server) {
this.server = server;
}
}
echo 'export PATH=$HOME/local/bin:$PATH' >> ~/.bashrc
. ~/.bashrc
mkdir ~/local
mkdir ~/node-latest-install
cd ~/node-latest-install
curl http://nodejs.org/dist/node-latest.tar.gz | tar xz --strip-components=1
./configure --prefix=~/local
make install # ok, fine, this step probably takes more than 30 seconds...
curl https://www.npmjs.org/install.sh | sh
@learningjs
learningjs / evt.js
Created April 28, 2015 04:00
[Stop event propagation]
function t (evt) {
evt.preventDefault();
evt.stopPropagation();
evt.stopImmediatePropagation();
...
}
@learningjs
learningjs / styles.less
Last active August 29, 2015 14:20 — forked from basarat/styles.less
// Style the find results
atom-text-editor::shadow .highlight.find-result .region {
background: rgb(163,163,0);
transition: background-color 0.2s, border-color 0.2s;
}
atom-text-editor::shadow .highlight.current-result .region,
atom-text-editor::shadow .highlight.current-result ~ .highlight.selection .region {
background: orange;
border-color: red;
}
passwd
systemctl enable sshd.service
systemctl start sshd.service
parted -s /dev/sda mklabel gpt
parted -s /dev/sda mkpart "primary" "fat16" "50MB" "60MB"
parted -s /dev/sda mkpart "primary" "ext4" "1%" "99%"
parted -s /dev/sda set 1 bios_grub on
mkfs.ext4 /dev/sda2
@learningjs
learningjs / gmail.sh
Last active August 29, 2015 14:25 — forked from smlb/gmail.sh
USER=your_username
PASS=your_passwd
COUNT=`curl -su $USER:$PASS https://mail.google.com/mail/feed/atom || echo "<fullcount>unknown number of</fullcount>"`
COUNT=`echo "$COUNT" | grep "<fullcount>" | sed -e s/"<fullcount>"// -e s/"<\/fullcount>"//`
echo $COUNT
if [ "$COUNT" != "0" ]; then
if [ "$COUNT" = "1" ];then
WORD="mail";
else
USER=`whoami`
KERNEL=`uname -r`
OS=`hostnamectl status | awk 'NR==6{print $3,$4}'`
HOST=`hostnamectl status | awk 'NR==1{print $3}'`
ROOT_TOT=`df -h | awk 'NR==2{print $2}' | sed 's/G//g'`
ROOT_OCCUPIED=`df -h | awk 'NR==2{print $3}' | sed 's/G//g'`
PACKAGES=`pacman -Qq | wc -l`
CPU=`echo -e : $(cat /proc/cpuinfo | awk 'NR==5{$1=$2=$3="";print}')`
CONNECTION=`[[ -x /usr/bin/iwgetid ]] && echo -e $(iwgetid -r) || echo "missing iw package"`
RES="\033[0m"