Skip to content

Instantly share code, notes, and snippets.

@victormejia
victormejia / httpWrapper.js
Last active April 12, 2017 23:50
Simple $http wrapper in AngularJS
angular.module('app')
.factory('AppSvc', function ($http, $q) {
return {
ajaxRq: function (req, cb) {
var deferred = $q.defer();
$http(req)
.success(function (data, status, headers, cfg) {
if (cb) {
deferred.resolve(cb({
status: status,
@victormejia
victormejia / sendFile.js
Last active January 4, 2016 03:59
Send File in Angular
scope.sendFile = function (el) {
scope.uploading = true;
var f = $(el).val(),
fObj = el.files[0];
if (f == '') {
return false;
}
var fPart = f.split('\\'),
origFilename = fPart[fPart.length - 1];
@victormejia
victormejia / FilePost.cs
Last active January 4, 2016 06:49
File POST in Web API
[HttpPost, Route("api/upload")]
public async Task<HttpResponseMessage> Upload()
{
if (!Request.Content.IsMimeMultipartContent())
return Request.CreateErrorResponse(HttpStatusCode.UnsupportedMediaType, "expected multi-part form content.");
var provider = new MultipartMemoryStreamProvider();
await Request.Content.ReadAsMultipartAsync(provider);
foreach (var file in provider.Contents)
{
angular.module('myMdl', []).config(['$httpProvider', function($httpProvider) {
$httpProvider.responseInterceptors.push([
'$q', '$templateCache', 'activeProfile',
function($q, $templateCache, activeProfile) {
// Keep track which HTML templates have already been modified.
var modifiedTemplates = {};
// Tests if there are any keep/omit attributes.
var HAS_FLAGS_EXP = /data-(keep|omit)/;
@victormejia
victormejia / phoneInput.html
Last active January 4, 2016 20:29
phone input directive for AngularJS
<div class="phoneFields">
<input type="text" id="phone" ng-model="area" maxlength="3"> -
<input type="text" ng-model="prefix" maxlength="3"> -
<input type="text" ng-model="suffix" maxlength="4">
</div>
var http = require("http"),
url = require("url"),
path = require("path"),
fs = require("fs")
port = process.argv[2] || 8888;
http.createServer(function(request, response) {
var uri = url.parse(request.url).pathname
, filename = path.join(process.cwd(), uri);
/*!
* Grunt
* $ npm install grunt-contrib-uglify grunt-autoprefixer grunt-contrib-cssmin grunt-contrib-imagemin grunt-contrib-sass grunt-contrib-watch grunt-contrib-concat grunt-contrib-clean grunt-contrib-jshint grunt-notify --save-dev
*/
module.exports = function(grunt) {
grunt.initConfig({
// Sass
@victormejia
victormejia / mongodb.md
Last active August 29, 2015 13:57
List of MondoDB commands I'm keeping track of as I go through the Tuts+ Learning MongoDB course https://tutsplus.com/course/learning-mongodb/.

Creating Databases, Collections, Documents

show databases

show dbs

connect to (or create) database

use dbname

insert new object (collection automatically created)

db.collection_name.insert(obj)

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.