Halaman

Minggu, 06 Agustus 2023

AJAX before and after jQuery 1.8

jQuery AJAX Before Version 1.8.0

Prior to jQuery version 1.8.0, the object returned from jQuery $.ajax() contained functions namely success(), error() and complete().

jQuery AJAX After Version 1.8.0

From jQuery 1.8.0 the $.ajax() function returns a jqXHR object that implements the promises interface (done(), fail(), always() etc.....). The success(), error() and complete() functions are now deprecated.

A quick reminder for those learning:

  • The .done() method replaces the deprecated jqXHR.success() method.
  • The .fail() method replaces the deprecated .error() method.
  • The .always() method replaces the deprecated .complete() method.

jQuery AJAX Before Version 1.8.0 Example

$.ajax({
    url: 'getname1.html',
    dataType: 'html',
    success: function (data, textStatus, xhr)
    {
        console.log(data);
    },
    error: function (xhr, textStatus, errorThrown)
    {
        console.log('error: '+textStatus);
    }
});

$.ajax({
    url: "getname1.html",
    cache: false
})
.done(function(data, textStatus, jqXHR)
{
    console.log(data);
})
.fail(function(jqXHR, textStatus, errorThrown)
{
    console.log('error: '+textStatus);
});


Senin, 18 Oktober 2021

Cassandra with C#

1. Using Microsoft Visual Studio, Create New Project for Console Application   


2. Configure the project 


3. My target Framework using NET 5.0 


4. Add Client Driver for Cassandra, click Tools menu ->NuGet Package Manager-> Manage NuGet Packages for Solution, then type CassandraCSharpDriver


so CassandraCSharpDriver package get installed



5. Create program 

using System;
using System.Collections;
using System.Collections.Generic;
using Cassandra;
using Cassandra.Mapping;

namespace Cassandra_con
{

    public class KeyspacesMain
    {
        public string Keyspace_name { get; set; }
        public bool Durable_writes { get; set; }
        public SortedDictionary<string string=""> Replication { get; set; }
    }

    class Program
    {
       const string MyDC = "datacenter1";
       const string MyIP = "localhost";
       const int MyPortNo = 9042;
       const string MyUID = "username";
       const string MyPass = "password";
       
        static void Main(string[] args)
        {
            Console.WriteLine("Hello Cassandra!");

            var cluster = Cluster.Builder()
                .AddContactPoints(MyIP)
                .WithPort(MyPortNo)
//              .WithLoadBalancingPolicy(new DCAwareRoundRobinPolicy(MyDC))
//              .WithAuthProvider(new PlainTextAuthProvider(MyUID, MyPass))
                .Build();

            var session = cluster.Connect();
            Console.WriteLine("Connected to cluster: " + cluster.Metadata.ClusterName);

            IMapper mapper = new Mapper(session);
            IEnumerable<keyspacesmain> datax = mapper.Fetch<keyspacesmain>("SELECT keyspace_name, durable_writes, replication FROM system_schema.keyspaces");
            Console.WriteLine("Keyspace Name      Durable Writes  Replication Factor"); 

            foreach (var row in datax)
            {
                Console.Write("{0}", row.Keyspace_name.PadRight(19));
                Console.Write("{0}     ", row.Durable_writes);
                
SortedDictionary<string string=""> obj = (SortedDictionary<string string="">)row.Replication;
                
                IDictionaryEnumerator dictEnum = obj.GetEnumerator();
                int spaces = 12;
                while (dictEnum.MoveNext())
                {
                    Console.WriteLine("Key= ".PadLeft(spaces) + dictEnum.Key + ", Value= " + dictEnum.Value);
                    spaces += 28;
                }
            }
        }
     }
 }

5. Output

Hello Cassandra!
Connected to cluster: Test Cluster
Keyspace Name      Durable Writes  Replication Factor
system_auth          True                     Key= class, Value= org.apache.cassandra.locator.SimpleStrategy
                                                          Key= replication_factor, Value= 1
system_schema     True                    Key= class, Value= org.apache.cassandra.locator.LocalStrategy
system_distributed True                    Key= class, Value= org.apache.cassandra.locator.SimpleStrategy
                                                          Key= replication_factor, Value= 3
system                    True                    Key= class, Value= org.apache.cassandra.locator.LocalStrategy
system_traces        True                     Key= class, Value= org.apache.cassandra.locator.SimpleStrategy
                                                          Key= replication_factor, Value= 2

So simple!


Cassandra Installation Using Docker On Windows

1. Make sure you have installed Docker Desktop for Windows.

2. Open Windows PowerShell

3. Download Cassandra image from the Docker Hub registry. 
Let’s pull Cassandra 4.01 image by type this command: docker pull cassandra:4.0.1


4. Start Cassandra

To start Cassandra, use docker run command that first creates a writeable container layer over the specified image, and then starts it using the specified command in a new container 

docker run --rm --name fercassandra -dp 9042:9042 cassandra:4.0.1


The --rm flag automatically removes the container (fercassandra) when it exits,
--name flag assign a name to the container
--detach , -d flag run container in background and print container ID
--publish , -p flag publish a container's port(s) to the host

5. Cassandra is running


6. CQL Shell

a.  Click CLI button to open window for interacting with Cassandra using CQL,

 then type this query: 

SELECT cluster_name, listen_address, listen_port, data_center, rpc_address, rpc_port FROM system.local;


b. Use docker exec command to run CQL Shell in a running container, then type the query:

c. Use docker exec command to run CQL shell cqlsh for interacting with Cassandra using CQL (the Cassandra Query Language). It is shipped with every Cassandra package, and can be found in the bin/ directory alongside the cassandra executable.


7.  Show more..
a. Use docker ps command to shows running containers:


b. Use docker port command to list port mappings or a specific mapping for the container:


That's enough for now, hope it helps someone.

Jumat, 04 Juni 2021

How to fix 404 Not Found Nginx - PHP

I'm working on moving applications from the old server to the new server and have to re-install. At this stage I configure PHP-based applications with related frameworks using Nginx as a web server. The problem that arises is the message Not Found with code 404, when the application runs the index.php file which then calls another file to run the actual process.

 

Next I created a test.php file to detect errors in the application and the tes.php file can run normally (code 200).

Information from curl shows the index.php file Found (302), but controller and action Not Found (404).



Status code HTTP/1.1 302 Found, indicates the requested resource resides temporarily under a different URI

The 404 Not Found message states that the server has not found anything matching the Request-URI.

The results of sudo tail -f /var/log/nginx/error.log and sudo tail -f /var/log/nginx/access.log don't show anything odd. The php files have been processed correctly, but the problem lies most likely in my Nginx configuration which is not suitable for processing php files.

I changed the configuration in the file /etc/nginx/sites-available/myweb.domain.com, which is from

location / {
try_files $uri $uri/ =404;
}
to 

location / {
try_files $uri $uri/ /index.php?$args;
}

Then do sudo service nginx restart and check the result:


As a result, my applications can run as they should and the status becomes HTTP/1.1 200 OK  or request has succeeded.

Jumat, 18 Oktober 2013

Oracle orasso

How to find lost ORASSO password
Login as orcladmin through Directory Manager and navigate to:
--> Entry Management
--> cn=OracleContext
--> cn=Products
--> cn=IAS
--> cn=IAS Infrastructure Databases
--> orclReferenceName=(yoursid.domain)
--> orclResourceName=ORASSO find the password in orclpasswords atribute on Properties tab.
also see --> orclResourceName=PORTAL
If you forget orcladmin, use this command from $ORACLE_HOME/bin directory
oidpasswd connect=yourDBconn unlock_su_acct=true enter new password...
OID DB user password: mynewpass

Kamis, 11 April 2013

Shrinking the SQL Server log

To backup a database, we could instruct SQL Server to truncate of the transaction log, using T-SQL command: BACKUP LOG db_name WITH TRUNCATE_ONLY. Log truncation remove transactions from the log file and the space remains allocated to the file. Sometimes as in my case below, you need to shrink the log file to reclaim the space.

In my case, I receive a backup file from SQL Server 2008, probably a full backup. After restoring the file and create a new database on my laptop, the used space is 160MB for the data and 52GB for the log file. My local disk free space 18 GB left, I need to shrinking the log file.

1. Check the database size property:
Select name, filename, convert(decimal(12,2), round(a.size/128.000,2)) as SizeMB,
convert(decimal(12,2), round(fileproperty(a.name,'SpaceUsed')/128.000,2)) as SpcUsedMB, 
convert(decimal(12,2), round((a.size-fileproperty(a.name,'SpaceUsed'))/128.000,2)) as FreeSpcMB
from dbo.sysfiles a

name        filename            SizeMB    SpcUsedMB  FreeSpcMB 
-----------------------------------------------------------------
Student     D:\DATA\STUDENT.mdf 155.69    149.50     6.19
Student_log D:\DATA\STUDENT.ldf 50861.94  362.09     50499.84

The FreeSpcMB shows 51GB and I try to reclaim the space of the log file to OS.

2. Change the database recover mode to simple
   ALTER DATABASE Student SET RECOVERY SIMPLE;
   GO

3. Do the Shrink the log file to 1 MB
   DBCC SHRINKFILE (Student_log, 1);
   GO

3. Reset the database recovery model.
   ALTER DATABASE Student SET RECOVERY FULL;
   GO
   SELECT name, recovery_model_desc FROM sys.databases;
   GO


Now, the OS has 70GB free space.

Sabtu, 23 Maret 2013

Eclipse: Cannot create a server using the selected type

I just install Tomcat version 7.0.37 to replace the old 7 version, but the new server could not be add to Eclipse with error message "Cannot create a server using the selected type".

To solve the problem, I've remove these files: org.eclipse.jst.server.tomcat.core.prefs  and org.eclipse.wst.server.core.prefs from /workspace/.metadata/.plugins/org.eclipse.core.runtime/.settings
and delete the old server.

After restarting Eclipse, "Define a New Server", now Tomcat works.