Skip to content

Instantly share code, notes, and snippets.

View lnmunhoz's full-sized avatar
⚛️
Building

Lucas N. Munhoz lnmunhoz

⚛️
Building
View GitHub Profile
@lnmunhoz
lnmunhoz / findCheckBoxes.js
Last active December 20, 2015 04:59
Find checked checkboxes in a table and get his name attribute.
$('#btn').click(function(){
var cbNames[];
$('#table td').find('input:checkbox:checked').each(function (i) {
cbNames[i] = ($(this).attr('name'));
});
});
@lnmunhoz
lnmunhoz / sendArrayToController.js
Last active December 20, 2015 04:59
Send an array to Controller in ASP.NET MVC
$.ajaxSettings.traditional = true; // <-- Important
$('#btn').click(function () {
var array = [];
var url = '/Controller/Action';
$.post(url, { array : array });
});
});
@lnmunhoz
lnmunhoz / getElementByName.js
Last active December 20, 2015 04:59
Get element by name
$("button[name=someName]").click(function () {
alert($(this).attr('name'));
});
@lnmunhoz
lnmunhoz / finalQ2.js
Last active December 20, 2015 12:08
Final Exam M101P Q2.
use enron
db.messages.aggregate([
{'$project' : {'_id' : '$_id' , 'From' : '$headers.From', 'To' : '$headers.To'}},
{'$unwind' : '$To'},
{'$group' : {'_id' : {'_id' : '$_id', 'From' : '$From'}, 'To' : {'$addToSet' : '$To'}}},
{'$unwind' : '$To'},
{'$group' : {'_id' : {'From' : '$_id.From', 'To' : '$To'}, 'emails' : {'$sum' : 1}}},
{'$sort' : {'emails' : -1}},
{'$limit' : 5}
])
@lnmunhoz
lnmunhoz / theReturnFlight1-6.js
Last active May 1, 2017 22:08
You've decided you only want to get photos of london. Use the data option of the $.ajax function to pass a location option. Get the location from the data-location on the #tour element using the data method.
DOM :
<div id="tour" data-location="london">
<button>Get Photos</button>
<ul class="photos">
</ul>
</div>
JS:
$(document).ready(function() {
var el = $("#tour")
@lnmunhoz
lnmunhoz / tfs_undo
Last active August 29, 2015 13:56
TFS - Undo Pending Changes
Nunca esquecer de entrar como admin.
cd C:\Arquivos de programas\Microsoft Visual Studio 10.0\Common7\IDE>
tf undo /workspace:workspacename;workspaceowner $/projectname/filename.cs
@lnmunhoz
lnmunhoz / AccountController.ExternalLoginConfirmation.cs
Last active August 29, 2015 14:08
This is for fix the facebook authentication errors that comes with erros in ASP.NET default template
[HttpPost]
[AllowAnonymous]
[ValidateAntiForgeryToken]
public async Task<ActionResult> ExternalLoginConfirmation(ExternalLoginConfirmationViewModel model, string returnUrl)
{
if (User.Identity.IsAuthenticated)
{
return RedirectToAction("Manage");
}
@lnmunhoz
lnmunhoz / server.js
Created December 16, 2014 20:04
server.js
'use strict';
var express = require('express');
var app = express();
var server = require('http').Server(app);
var bodyParser = require('body-parser');
var port = process.env.PORT || 3000;
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({extended: true}));
@lnmunhoz
lnmunhoz / index.html
Created February 11, 2015 17:14
RealTime chart with ChartJS, Socket.io and KnockoutJS
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="author" content="lnmunhoz">
<script src="http://code.jquery.com/jquery-1.9.1.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/knockout/2.1.0/knockout-min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/1.0.1/Chart.js"></script>
@lnmunhoz
lnmunhoz / saveFileStream.cs
Created March 24, 2015 19:42
Save FileStream into Disk
// file is our stream
var fileStream = File.Create(@"..\"+ file.FileName, (int) file.Length);
var bytesInStream = new byte[file.Length];
file.Read(bytesInStream, 0, bytesInStream.Length);
fileStream.Write(bytesInStream, 0, bytesInStream.Length);