Skip to content

Instantly share code, notes, and snippets.

@sergioceron
sergioceron / gist:3333515
Created August 12, 2012 18:10
Connect to Windows DSN from C++
#include <windows.h>
#include <sqlext.h>
#include <sql.h>
...
HENV hEnv = NULL; // for allocating memory usingSQLAllocEnv
HDBC hDBC = NULL; // connection handler
HSTMT hStmt = NULL; // statement handler
UCHAR szDSN[SQL_MAX_DSN_LENGTH] = "myDSN"; // DataSourceName (config in windows control panel)
@sergioceron
sergioceron / gist:3333531
Created August 12, 2012 18:14
Perform query DSN Windows C++
int retcode = 0;
retcode = SQLAllocStmt (hDBC, &hStmt);
retcode = SQLPrepare (hStmt, (UCHAR *)sql, SQL_NTS);
retcode = SQLExecute (hStmt);
//SQLBindCol(hStmt, no+1, SQL_C_CHAR, szModel1, sizeof(szModel1), &cbModel1);
retcode = SQLFetch (hStmt);
if (retcode == SQL_ERROR)
{
@sergioceron
sergioceron / gist:3333539
Created August 12, 2012 18:16
Get resultset to struct DSN Windows c++
retcode = SQLAllocStmt (hDBC, &hStmt);
retcode = SQLPrepare (hStmt, (UCHAR *)sqls, SQL_NTS);
retcode = SQLExecute (hStmt);
SQLBindCol(hStmt, 3, SQL_C_SLONG, &szModel, 5, &ic);
SQLBindCol(hStmt, 2, SQL_C_CHAR, szModel1, sizeof(szModel1), &cbModel);
SQLBindCol(hStmt, 4, SQL_C_FLOAT, &szModel2, 5, &cbModel);
SQLBindCol(hStmt, 5, SQL_C_FLOAT, &szModel3, 5, &cbModel);
SQLBindCol(hStmt, 6, SQL_C_SLONG, &szModel4, 5, &ic);
SQLBindCol(hStmt, 7, SQL_C_CHAR, szModel5, sizeof(szModel5), &cbModel);
@sergioceron
sergioceron / WakeOnLan.java
Created February 2, 2013 18:52
WakeOnLan Java
/**
* Created by IntelliJ IDEA.
* User: sergio
* Date: 7/12/12
* Time: 05:31 PM
* To change this template use File | Settings | File Templates.
*/
import java.io.*;
import java.net.*;
@sergioceron
sergioceron / WakeOnLan.java
Created February 2, 2013 18:52
WakeOnLan
/**
* Created by IntelliJ IDEA.
* User: sergio
* Date: 7/12/12
* Time: 05:31 PM
* To change this template use File | Settings | File Templates.
*/
import java.io.*;
import java.net.*;
@sergioceron
sergioceron / UIList.java
Created June 2, 2013 19:41
Detect double click on a JTable Cell
if (e.getClickCount() == 2) {
JTable target = (JTable) e.getSource();
int row = target.getSelectedRow();
Object value = target.getModel().getValueAt(row, 0);
for (ItemListener il : listeners) {
il.onItemDoubleClick(this, value, row);
}
}
@sergioceron
sergioceron / gist:9215314
Created February 25, 2014 19:00
Use jQuery Datatables API with AngularJS
$scope.$watchCollection( 'myCollection', function( oldCollection, newCollection ) {
if( oldCollection === newCollection ) return;
// Gives the time to destroy dataTable, which is immediately
$( '#dataTable' ).dataTable().fnDestroy();
$timeout(function () {
// After a few time, create the dataTable when DOM render is complete
$( '#dataTable' ).dataTable();
});
});
#!/bin/bash
#
# This script installs and configures couchdb on a fresh Amazon Linux AMI instance.
#
# Must be run with root privileges
# Tested with Amazon Linux AMI release 2011.02.1.1 (ami-8c1fece5)
#
export BUILD_DIR="$PWD"
@sergioceron
sergioceron / gist:9475068
Created March 10, 2014 21:44
New initialization way to collections in java
List<String> list = new ArrayList<String>() {
{
add("String A");
add("String B");
add("String C");
}
};
@sergioceron
sergioceron / gist:9516914
Created March 12, 2014 21:35
Run process in background (SSH, Amazon)
sudo nohup command &