Skip to content

Instantly share code, notes, and snippets.

View samueleresca's full-sized avatar

Samuele Resca samueleresca

View GitHub Profile
<html>
<head>
<title>JSON - JSONP tests</title>
<!--Include jquery-->
<script src="http://code.jquery.com/jquery-1.8.2.min.js"></script>
<script type="text/javascript">
$(function(){
//DEF response
var data = {};
data.title = "title";
//DEPENDENCIES
var express = require('express');
//Initialize Express.js
var app = express();
//JSONP Get Request
app.get('/endpointJSONP', function(req, res){
//LOG
//REPO
var objArray = [
{id: 1, description: "Cuba libre", price: 6.00},
{id: 2,description: "Beer",price: 3.50},
{id: 3, description: "Vodka Lemon", price: 5.00},
{id: 4, description: "Long island", price: 5.50},
{id: 5, description: "Caipiroska", price: 7.50}
]
/*
*Contains all configuration used by GoogleApiClass
*/
var configurations = {
geolocationFailed: "Error: Geolocation failed.",
geolocationNotSupported: "Error: Geolocation isn\'t supported",
locationFound: "You are here",
defaultLocation: new google.maps.LatLng(44.493587, 11.346584) //Bologna
};
//Class Telefilm
[Serializable]
public class Telefilm
{
public int TelefilmId { get; set; }
public string TelefilmName { get; set; }
public DateTime CreateDate { get; set; }
public bool ShouldSerializeCreateDate() {
return (!TelefilmName.Equals("Californication")); //Bool EXP
[TestClass]
public class ConditionalSerializingTests
{
public Telefilm[] Telefilms = new Telefilm[]{
new Telefilm{TelefilmId=1 , TelefilmName="Slevin" , CreateDate= new DateTime(1999,04,23)},
new Telefilm{TelefilmId=2 , TelefilmName="Scrubs" , CreateDate= new DateTime(2001,02,08) },
new Telefilm{TelefilmId=3 , TelefilmName="HIMYM" , CreateDate= new DateTime(2004,12,05)},
new Telefilm{TelefilmId=4 , TelefilmName="Californication", CreateDate= new DateTime(2010,02,12)}
public static IQueryable Take(this IQueryable source, int count)
{
if (source == null)
throw Error.ArgumentNull("source");
return source.Provider.CreateQuery(
Expression.Call(
null,
((MethodInfo)MethodBase.GetCurrentMethod()).MakeGenericMethod(typeof(TSource)),
new Expression[] { source.Expression, Expression.Constant(count) }
));
public static IEnumerable Take(this IEnumerable source, int count)
{
if (source == null) throw Error.ArgumentNull("source");
return TakeIterator(source, count);
}
static IEnumerable TakeIterator(IEnumerable source, int count)
{
if (count > 0)
{
[TestMethod]
public void IEnumerableBehavior()
{
IEnumerable<Product> products = dc.Product
//This expression produces an SQL query
.Where(p => p.Name.Contains("LL"));
//IEnumerable: the following statement is an in-memory query
products = products.Take<Product>(100);
}