Skip to content

Instantly share code, notes, and snippets.

@btroncone
btroncone / ngrxintro.md
Last active March 5, 2025 20:40
A Comprehensive Introduction to @ngrx/store - Companion to Egghead.io Series

Comprehensive Introduction to @ngrx/store

By: @BTroncone

Also check out my lesson @ngrx/store in 10 minutes on egghead.io!

Update: Non-middleware examples have been updated to ngrx/store v2. More coming soon!

Table of Contents

import React from "react";
import { render } from "react-dom";
const ParentComponent = React.createClass({
getDefaultProps: function() {
console.log("ParentComponent - getDefaultProps");
},
getInitialState: function() {
console.log("ParentComponent - getInitialState");
return { text: "" };
@gaearon
gaearon / reducers.js
Last active December 11, 2020 14:56
How I'd do code splitting in Redux (pseudo code, not tested!)
import { combineReducers } from 'redux';
import users from './reducers/users';
import posts from './reducers/posts';
export default function createReducer(asyncReducers) {
return combineReducers({
users,
posts,
...asyncReducers
});
<responsive>
<div ng-switch='screenSize'>
<div ng-switch-when='small'>
<h1>Small Screen</h1>
</div>
<div ng-switch-when='medium'>
<h1>Medium Screen</h1>
</div>
<div ng-switch-when='large'>
<h1>Large Screen</h1>
@yangboz
yangboz / AngularJS+WebSocket
Created December 15, 2014 02:59
AngularJS+WebSocket
//WebSocket
.factory('WebsocketService', ['$rootScope', '$timeout', function ($rootScope, $timeout) {
var _ws;
var _username = '';
var messages = [];
var users = [];
function onMessage(e) {
var data = JSON.parse(decodeURIComponent(e.data));
@ipmb
ipmb / ratelimit.nginxconf
Last active July 21, 2024 05:37
Nginx reverse proxy with rate limiting
upstream myapp {
server 127.0.0.1:8081;
}
limit_req_zone $binary_remote_addr zone=login:10m rate=1r/s;
server {
listen 443 ssl spdy;
server_name _;
(function () {
'use strict';
angular.module('main')
.provider('cache', function () {
// #region initialization
var storage;
@carbonrobot
carbonrobot / rightClick.directive.js
Created October 15, 2014 19:29
Angular Right Click Directive
(function () {
/*
* @name ngRightClick
* @type Directive
* @desc Binds the right click to a javascript function by using the ng-right-click attribute
*/
function ngRightClick($parse) {
return function (scope, element, attrs) {
(function () {
'use strict';
// Define the factory on the module.
// Inject the dependencies.
// Point to the factory definition function.
angular.module('brew-everywhere').factory('messaging_service',
[messaging_service]);
function messaging_service() {
@mlynch
mlynch / auth.markdown
Last active September 4, 2020 18:11
AngularJS Authentication and CORS

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.