Skip to content

Instantly share code, notes, and snippets.

@dcsg
dcsg / TruncateFilter.js
Created April 24, 2012 10:31
Truncate Filter for AngularJS v1.0
// add the filter to your application module
angular.module('yourAppName', ['filters']);
/**
* Truncate Filter
* @Param string
* @Param int, default = 10
* @Param string, default = "..."
* @return string
*/
@triceam
triceam / gist:4658021
Created January 28, 2013 18:50
Detecting PhoneGap/Ripple emulator via JavaScript
myFunction( param ) {
var emulated = window.tinyHippos != undefined;
if ( emulated ){
//do something specific to emulated environment;
return;
}
///do something else...
import express from 'express';
const app = express();
if (IS_DEV) {
require('piping')();
}
//express routes, etc.
export default app;

Proposed module resolution strategy

Proposed set of rules is an extension to baseUrl based mechanics used by RequireJS or SystemJS.

Core elements of the system are baseUrl and path mappings. Resolution process describes how they are used together.

BaseUrl

All non-rooted paths are computed relative to baseUrl. Value of baseUrl is determined as either:

import { Pipe } from 'angular2/core.js';
/**
* Map to Iteratble Pipe
*
* It accepts Objects and [Maps](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map)
*
* Example:
*
* <div *ngFor="#keyValuePair of someObject | mapToIterable">
@matheus-santos
matheus-santos / cheat_sheet_socketio
Last active May 1, 2019 19:23
SocketIO cheat sheet to emit messages through sockets
// SocketIO cheat sheet
// SocketIO is a library that makes websockets communications easier.
// Page: http://socket.io/
// ref: http://stackoverflow.com/a/10099325
// send to current request socket client
socket.emit('message', "this is a test");
// sending to all clients, include sender
io.sockets.emit('message', "this is a test");
@cultofmetatron
cultofmetatron / gist:5349630
Created April 9, 2013 21:38
passport ajax capable authenticate
app.post('/login', function(req, res) {
console.log(res);
passport.authenticate('local', function(err, user) {
if (req.xhr) {
//thanks @jkevinburton
if (err) { return res.json({ error: err.message }); }
if (!user) { return res.json({error : "Invalid Login"}); }
req.login(user, {}, function(err) {
if (err) { return res.json({error:err}); }
return res.json(
@nojaf
nojaf / package.json
Created November 21, 2015 10:19
From TypeScript to Babel to ES5 with webpack
{
"name": "webpack-ts-babel",
"version": "1.0.0",
"description": "",
"main": "webpack.config.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
@jrthib
jrthib / AnotherController.js
Created July 16, 2014 23:50
Factory using promises to start the socket.io authentication and session after logging into an Angular app.
(function() {
'use strict';
function AnotherController($scope, socket) {
// use the socket factory through your app, but you must use socket.then
// so that the actions occur once the socket is established
socket.then(function(socket) {
socket.emit('some_socket_event', {});
});
@branneman
branneman / app.js
Last active February 5, 2021 21:58
Node.js application entry-point files
#!/usr/bin/env node
'use strict';
var spawn = require('child_process').spawn;
var args = [
'--harmony',
'app/bootstrap.js'
];