select rows via waterline/ sails.js

odel.find({field: 'value'}, {fields: ['id', 'name']})
    .paginate({page: 1}, {limit: 10)
    .exec(function(err, results) {
        if(err) {
            res.badRequest('reason');
        }
        res.jsonx(results);
    });
Advertisements

#code, #orm, #sails-js, #waterline

Connect to a local database in C#


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using System.Windows;

namespace WpfApplication1
{
 class DBClass
 {
 private SqlConnection sqlcon;
 private SqlCommand sqlcom;
 public DBClass()
 {
 string executable = System.Reflection.Assembly.GetExecutingAssembly().Location;
 string path = (System.IO.Path.GetDirectoryName(executable));
 MessageBox.Show(path);
 AppDomain.CurrentDomain.SetData("DataDirectory", path);
 string sqlCon = @"Data Source=.\SQLEXPRESS;" +
 @"AttachDbFilename=|DataDirectory|\testsystem.mdf;
 Integrated Security=True;
 Connect Timeout=30;
 User Instance=True";
 sqlcon = new SqlConnection(sqlCon);
 
 sqlcom = new SqlCommand();
 }

 public SqlDataReader executeQuery(String query){
 SqlDataReader reader;
 this.sqlcom.CommandText = query;
 this.sqlcom.CommandType = CommandType.Text;
 this.sqlcom.Connection = this.sqlcon;

 this.sqlcon.Open();

 reader = this.sqlcom.ExecuteReader();

 return reader;

 }

 public void closeConnection() {
 this.sqlcon.Close();
 }
 }
}



#code, #csharp, #database, #local-database, #sql-server

checking a checkbox in jquery

for JQuery 1.6+

$('.myCheckbox').prop('checked', true);
$('.myCheckbox').prop('checked', false);

for below 1.6

$('.myCheckbox').attr('checked', true);
$('.myCheckbox').attr('checked', false);

#checkbox, #code, #jquery

How to fix “Headers already sent” error in PHP

The following worked for me

<?php
  ob_start();

  // code 

 ob_end_flush();
?> 

Source: http://stackoverflow.com/questions/8028957/how-to-fix-headers-already-sent-error-in-php

#code, #php, #stackoverflow

Solution of the problem Life,the Universe and Everything in two new programming language

Ok, I just solved the problem stated in http://www.codechef.com/problems/TEST by using two new programming language, Go and Lua.
Here goes the code,
GO:

package main

import "fmt"

func main() {
for value := 0; ; {
fmt.Scanln(&value)
if value == 42 {
break
}
fmt.Println(value)

}
}

And now for Lua:

local ans
ans = io.read()
ans = tonumber(ans)
while ans ~= 42 do
print(ans)
ans = io.read()
ans = tonumber(ans)
end

Well I admit, lua is a true beauty, where Go looks like a rough one.   Be with me via twitter to know my micro thoughts.

#code, #codechef, #golang, #lua, #programming-contest

PHP Array Multisort Object: Sort multidimensional array by different columns – PHP Classes

PHP Array Multisort Object: Sort multidimensional array by different columns – PHP Classes.

#code, #php

[CODE] function to get google place recommandations


function fetch_google_venue_recommandation($place_name,$long,$lat){
 global $logger;
 $url = "https://maps.googleapis.com/maps/api/place/textsearch/json?query=" . $place_name . "&sensor=true&location=".$long.",".$lat. "&key=" . GOOGLE_APP_KEY;
 $places = null;
 $logger->debug($url);
 $ch = curl_init($url);
 curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
 curl_setopt($ch, CURLOPT_HEADER, 0);
 curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
 $data = curl_exec($ch); // Yelp response
 curl_close($ch);
 $response = json_decode($data);
 return $response;
 }

#code, #curl, #google, #google-api, #php

internet explorer – Detect IE version in Javascript – Stack Overflow

I did the following:

function isIE (){var myNav = navigator.userAgent.toLowerCase();return(myNav.indexOf('msie')!=-1)? parseInt(myNav.split('msie')[1]):false;}
if(isIE()){// is IE}else{// Other browser}

internet explorer – Detect IE version in Javascript – Stack Overflow.

#cascading-style-sheets, #code, #ie, #javascript, #stack-overflow, #stackoverflow

Get unix date time of 15 days ago in php

$date = date('Y-m-d H:i:s', strtotime("-15 days"));

#code, #php

Return the last day of the month, the bad and ugly way (but great way!)

Taken from http://javascript.about.com/library/bllday.htm


function daysInMonth(month,year) {
var m = [31,28,31,30,31,30,31,31,30,31,30,31];
if (month != 2) return m[month - 1];
if (year%4 != 0) return m[1];
if (year%100 == 0 && year%400 != 0) return m[1];
return m[1] + 1;
}

#code, #date, #javascript