WeixiangYan/CodeTransOcean huggingface dataset:
Task: File modification time

C: #include <sys/stat.h>
#include <stdio.h>
#include <time.h>
#include <utime.h>

const char *filename = "input.txt";

int main() {
  struct stat foo;
  time_t mtime;
  struct utimbuf new_times;

  if (stat(filename, &foo) < 0) {
    perror(filename);
    return 1;
  }
  mtime = foo.st_mtime; 

  new_times.actime = foo.st_atime; 
  new_times.modtime = time(NULL);    
  if (utime(filename, &new_times) < 0) {
    perror(filename);
    return 1;
  }

  return 0;
}





Java: import java.io.File;
import java.util.Date;
public class FileModificationTimeTest {
   public static void test(String type, File file) {
       long t = file.lastModified();
       System.out.println("The following " + type + " called " + file.getPath() +
            (t == 0 ? " does not exist." : " was modified at " + new Date(t).toString() )
       );
       System.out.println("The following " + type + " called " + file.getPath() + 
            (!file.setLastModified(System.currentTimeMillis()) ? " does not exist." : " was modified to current time." )
       );
       System.out.println("The following " + type + " called " + file.getPath() + 
            (!file.setLastModified(t) ? " does not exist." : " was modified to previous time." )
       );
   }
   public static void main(String args[]) {
       test("file", new File("output.txt"));
       test("directory", new File("docs"));
   }
}
Task: File modification time


C++: #include <boost/filesystem/operations.hpp>
#include <ctime>
#include <iostream>

int main( int argc , char *argv[ ] ) {
   if ( argc != 2 ) {
      std::cerr << "Error! Syntax: moditime <filename>!\n" ;
      return 1 ;
   }
   boost::filesystem::path p( argv[ 1 ] ) ;
   if ( boost::filesystem::exists( p ) ) {
      std::time_t t = boost::filesystem::last_write_time( p ) ;
      std::cout << "On " << std::ctime( &t ) << " the file " << argv[ 1 ] 
	 << " was modified the last time!\n" ;
      std::cout << "Setting the modification time to now:\n" ;
      std::time_t n = std::time( 0 ) ;
      boost::filesystem::last_write_time( p , n ) ; 
      t = boost::filesystem::last_write_time( p ) ;
      std::cout << "Now the modification time is " << std::ctime( &t ) << std::endl ;
      return 0 ;
   } else {
      std::cout << "Could not find file " << argv[ 1 ] << '\n' ;
      return 2 ;
   }
}


C#: using System;
using System.IO;

Console.WriteLine(File.GetLastWriteTime("file.txt"));
File.SetLastWriteTime("file.txt", DateTime.Now);
Task: File modification time


C++: #include <boost/filesystem/operations.hpp>
#include <ctime>
#include <iostream>

int main( int argc , char *argv[ ] ) {
   if ( argc != 2 ) {
      std::cerr << "Error! Syntax: moditime <filename>!\n" ;
      return 1 ;
   }
   boost::filesystem::path p( argv[ 1 ] ) ;
   if ( boost::filesystem::exists( p ) ) {
      std::time_t t = boost::filesystem::last_write_time( p ) ;
      std::cout << "On " << std::ctime( &t ) << " the file " << argv[ 1 ] 
	 << " was modified the last time!\n" ;
      std::cout << "Setting the modification time to now:\n" ;
      std::time_t n = std::time( 0 ) ;
      boost::filesystem::last_write_time( p , n ) ; 
      t = boost::filesystem::last_write_time( p ) ;
      std::cout << "Now the modification time is " << std::ctime( &t ) << std::endl ;
      return 0 ;
   } else {
      std::cout << "Could not find file " << argv[ 1 ] << '\n' ;
      return 2 ;
   }
}



Go: package main

import (
    "fmt"
    "os"
    "syscall"
    "time"
)

var filename = "input.txt"

func main() {
    foo, err := os.Stat(filename)
    if err != nil {
        fmt.Println(err)
        return
    }
    fmt.Println("mod time was:", foo.ModTime())
    mtime := time.Now()
    atime := mtime 
    
    if ss, ok := foo.Sys().(*syscall.Stat_t); ok {
        atime = time.Unix(ss.Atim.Sec, ss.Atim.Nsec)
    }
    os.Chtimes(filename, atime, mtime)
    fmt.Println("mod time now:", mtime)
}
Task: File modification time


C++: #include <boost/filesystem/operations.hpp>
#include <ctime>
#include <iostream>

int main( int argc , char *argv[ ] ) {
   if ( argc != 2 ) {
      std::cerr << "Error! Syntax: moditime <filename>!\n" ;
      return 1 ;
   }
   boost::filesystem::path p( argv[ 1 ] ) ;
   if ( boost::filesystem::exists( p ) ) {
      std::time_t t = boost::filesystem::last_write_time( p ) ;
      std::cout << "On " << std::ctime( &t ) << " the file " << argv[ 1 ] 
	 << " was modified the last time!\n" ;
      std::cout << "Setting the modification time to now:\n" ;
      std::time_t n = std::time( 0 ) ;
      boost::filesystem::last_write_time( p , n ) ; 
      t = boost::filesystem::last_write_time( p ) ;
      std::cout << "Now the modification time is " << std::ctime( &t ) << std::endl ;
      return 0 ;
   } else {
      std::cout << "Could not find file " << argv[ 1 ] << '\n' ;
      return 2 ;
   }
}







VB: Dim file As New IO.FileInfo("test.txt")


Dim createTime = file.CreationTime
file.CreationTime = createTime.AddHours(1)


Dim writeTime = file.LastWriteTime
file.LastWriteTime = writeTime.AddHours(1)
 

Dim accessTime = file.LastAccessTime
file.LastAccessTime = accessTime.AddHours(1)
Task: File modification time



C#: using System;
using System.IO;

Console.WriteLine(File.GetLastWriteTime("file.txt"));
File.SetLastWriteTime("file.txt", DateTime.Now);


Go: package main

import (
    "fmt"
    "os"
    "syscall"
    "time"
)

var filename = "input.txt"

func main() {
    foo, err := os.Stat(filename)
    if err != nil {
        fmt.Println(err)
        return
    }
    fmt.Println("mod time was:", foo.ModTime())
    mtime := time.Now()
    atime := mtime 
    
    if ss, ok := foo.Sys().(*syscall.Stat_t); ok {
        atime = time.Unix(ss.Atim.Sec, ss.Atim.Nsec)
    }
    os.Chtimes(filename, atime, mtime)
    fmt.Println("mod time now:", mtime)
}
Task: File modification time



C#: using System;
using System.IO;

Console.WriteLine(File.GetLastWriteTime("file.txt"));
File.SetLastWriteTime("file.txt", DateTime.Now);





Python: import os


modtime = os.path.getmtime('filename')


os.utime('path', (actime, mtime))


os.utime('path', (os.path.getatime('path'), mtime))


os.utime('path', None)
Task: File modification time




Go: package main

import (
    "fmt"
    "os"
    "syscall"
    "time"
)

var filename = "input.txt"

func main() {
    foo, err := os.Stat(filename)
    if err != nil {
        fmt.Println(err)
        return
    }
    fmt.Println("mod time was:", foo.ModTime())
    mtime := time.Now()
    atime := mtime 
    
    if ss, ok := foo.Sys().(*syscall.Stat_t); ok {
        atime = time.Unix(ss.Atim.Sec, ss.Atim.Nsec)
    }
    os.Chtimes(filename, atime, mtime)
    fmt.Println("mod time now:", mtime)
}


Java: import java.io.File;
import java.util.Date;
public class FileModificationTimeTest {
   public static void test(String type, File file) {
       long t = file.lastModified();
       System.out.println("The following " + type + " called " + file.getPath() +
            (t == 0 ? " does not exist." : " was modified at " + new Date(t).toString() )
       );
       System.out.println("The following " + type + " called " + file.getPath() + 
            (!file.setLastModified(System.currentTimeMillis()) ? " does not exist." : " was modified to current time." )
       );
       System.out.println("The following " + type + " called " + file.getPath() + 
            (!file.setLastModified(t) ? " does not exist." : " was modified to previous time." )
       );
   }
   public static void main(String args[]) {
       test("file", new File("output.txt"));
       test("directory", new File("docs"));
   }
}
Task: File modification time





Java: import java.io.File;
import java.util.Date;
public class FileModificationTimeTest {
   public static void test(String type, File file) {
       long t = file.lastModified();
       System.out.println("The following " + type + " called " + file.getPath() +
            (t == 0 ? " does not exist." : " was modified at " + new Date(t).toString() )
       );
       System.out.println("The following " + type + " called " + file.getPath() + 
            (!file.setLastModified(System.currentTimeMillis()) ? " does not exist." : " was modified to current time." )
       );
       System.out.println("The following " + type + " called " + file.getPath() + 
            (!file.setLastModified(t) ? " does not exist." : " was modified to previous time." )
       );
   }
   public static void main(String args[]) {
       test("file", new File("output.txt"));
       test("directory", new File("docs"));
   }
}




VB: Dim file As New IO.FileInfo("test.txt")


Dim createTime = file.CreationTime
file.CreationTime = createTime.AddHours(1)


Dim writeTime = file.LastWriteTime
file.LastWriteTime = writeTime.AddHours(1)
 

Dim accessTime = file.LastAccessTime
file.LastAccessTime = accessTime.AddHours(1)
Task: File modification time




Go: package main

import (
    "fmt"
    "os"
    "syscall"
    "time"
)

var filename = "input.txt"

func main() {
    foo, err := os.Stat(filename)
    if err != nil {
        fmt.Println(err)
        return
    }
    fmt.Println("mod time was:", foo.ModTime())
    mtime := time.Now()
    atime := mtime 
    
    if ss, ok := foo.Sys().(*syscall.Stat_t); ok {
        atime = time.Unix(ss.Atim.Sec, ss.Atim.Nsec)
    }
    os.Chtimes(filename, atime, mtime)
    fmt.Println("mod time now:", mtime)
}




Python: import os


modtime = os.path.getmtime('filename')


os.utime('path', (actime, mtime))


os.utime('path', (os.path.getatime('path'), mtime))


os.utime('path', None)
Task: File modification time




Go: package main

import (
    "fmt"
    "os"
    "syscall"
    "time"
)

var filename = "input.txt"

func main() {
    foo, err := os.Stat(filename)
    if err != nil {
        fmt.Println(err)
        return
    }
    fmt.Println("mod time was:", foo.ModTime())
    mtime := time.Now()
    atime := mtime 
    
    if ss, ok := foo.Sys().(*syscall.Stat_t); ok {
        atime = time.Unix(ss.Atim.Sec, ss.Atim.Nsec)
    }
    os.Chtimes(filename, atime, mtime)
    fmt.Println("mod time now:", mtime)
}





VB: Dim file As New IO.FileInfo("test.txt")


Dim createTime = file.CreationTime
file.CreationTime = createTime.AddHours(1)


Dim writeTime = file.LastWriteTime
file.LastWriteTime = writeTime.AddHours(1)
 

Dim accessTime = file.LastAccessTime
file.LastAccessTime = accessTime.AddHours(1)
Task: File modification time

C: #include <sys/stat.h>
#include <stdio.h>
#include <time.h>
#include <utime.h>

const char *filename = "input.txt";

int main() {
  struct stat foo;
  time_t mtime;
  struct utimbuf new_times;

  if (stat(filename, &foo) < 0) {
    perror(filename);
    return 1;
  }
  mtime = foo.st_mtime; 

  new_times.actime = foo.st_atime; 
  new_times.modtime = time(NULL);    
  if (utime(filename, &new_times) < 0) {
    perror(filename);
    return 1;
  }

  return 0;
}







Python: import os


modtime = os.path.getmtime('filename')


os.utime('path', (actime, mtime))


os.utime('path', (os.path.getatime('path'), mtime))


os.utime('path', None)
Task: File modification time

C: #include <sys/stat.h>
#include <stdio.h>
#include <time.h>
#include <utime.h>

const char *filename = "input.txt";

int main() {
  struct stat foo;
  time_t mtime;
  struct utimbuf new_times;

  if (stat(filename, &foo) < 0) {
    perror(filename);
    return 1;
  }
  mtime = foo.st_mtime; 

  new_times.actime = foo.st_atime; 
  new_times.modtime = time(NULL);    
  if (utime(filename, &new_times) < 0) {
    perror(filename);
    return 1;
  }

  return 0;
}








VB: Dim file As New IO.FileInfo("test.txt")


Dim createTime = file.CreationTime
file.CreationTime = createTime.AddHours(1)


Dim writeTime = file.LastWriteTime
file.LastWriteTime = writeTime.AddHours(1)
 

Dim accessTime = file.LastAccessTime
file.LastAccessTime = accessTime.AddHours(1)
Task: File modification time



C#: using System;
using System.IO;

Console.WriteLine(File.GetLastWriteTime("file.txt"));
File.SetLastWriteTime("file.txt", DateTime.Now);



Java: import java.io.File;
import java.util.Date;
public class FileModificationTimeTest {
   public static void test(String type, File file) {
       long t = file.lastModified();
       System.out.println("The following " + type + " called " + file.getPath() +
            (t == 0 ? " does not exist." : " was modified at " + new Date(t).toString() )
       );
       System.out.println("The following " + type + " called " + file.getPath() + 
            (!file.setLastModified(System.currentTimeMillis()) ? " does not exist." : " was modified to current time." )
       );
       System.out.println("The following " + type + " called " + file.getPath() + 
            (!file.setLastModified(t) ? " does not exist." : " was modified to previous time." )
       );
   }
   public static void main(String args[]) {
       test("file", new File("output.txt"));
       test("directory", new File("docs"));
   }
}
Task: File modification time



C#: using System;
using System.IO;

Console.WriteLine(File.GetLastWriteTime("file.txt"));
File.SetLastWriteTime("file.txt", DateTime.Now);






VB: Dim file As New IO.FileInfo("test.txt")


Dim createTime = file.CreationTime
file.CreationTime = createTime.AddHours(1)


Dim writeTime = file.LastWriteTime
file.LastWriteTime = writeTime.AddHours(1)
 

Dim accessTime = file.LastAccessTime
file.LastAccessTime = accessTime.AddHours(1)
Task: File modification time





Java: import java.io.File;
import java.util.Date;
public class FileModificationTimeTest {
   public static void test(String type, File file) {
       long t = file.lastModified();
       System.out.println("The following " + type + " called " + file.getPath() +
            (t == 0 ? " does not exist." : " was modified at " + new Date(t).toString() )
       );
       System.out.println("The following " + type + " called " + file.getPath() + 
            (!file.setLastModified(System.currentTimeMillis()) ? " does not exist." : " was modified to current time." )
       );
       System.out.println("The following " + type + " called " + file.getPath() + 
            (!file.setLastModified(t) ? " does not exist." : " was modified to previous time." )
       );
   }
   public static void main(String args[]) {
       test("file", new File("output.txt"));
       test("directory", new File("docs"));
   }
}



Python: import os


modtime = os.path.getmtime('filename')


os.utime('path', (actime, mtime))


os.utime('path', (os.path.getatime('path'), mtime))


os.utime('path', None)
Task: File modification time







Python: import os


modtime = os.path.getmtime('filename')


os.utime('path', (actime, mtime))


os.utime('path', (os.path.getatime('path'), mtime))


os.utime('path', None)


VB: Dim file As New IO.FileInfo("test.txt")


Dim createTime = file.CreationTime
file.CreationTime = createTime.AddHours(1)


Dim writeTime = file.LastWriteTime
file.LastWriteTime = writeTime.AddHours(1)
 

Dim accessTime = file.LastAccessTime
file.LastAccessTime = accessTime.AddHours(1)
Task: File modification time


C++: #include <boost/filesystem/operations.hpp>
#include <ctime>
#include <iostream>

int main( int argc , char *argv[ ] ) {
   if ( argc != 2 ) {
      std::cerr << "Error! Syntax: moditime <filename>!\n" ;
      return 1 ;
   }
   boost::filesystem::path p( argv[ 1 ] ) ;
   if ( boost::filesystem::exists( p ) ) {
      std::time_t t = boost::filesystem::last_write_time( p ) ;
      std::cout << "On " << std::ctime( &t ) << " the file " << argv[ 1 ] 
	 << " was modified the last time!\n" ;
      std::cout << "Setting the modification time to now:\n" ;
      std::time_t n = std::time( 0 ) ;
      boost::filesystem::last_write_time( p , n ) ; 
      t = boost::filesystem::last_write_time( p ) ;
      std::cout << "Now the modification time is " << std::ctime( &t ) << std::endl ;
      return 0 ;
   } else {
      std::cout << "Could not find file " << argv[ 1 ] << '\n' ;
      return 2 ;
   }
}




Java: import java.io.File;
import java.util.Date;
public class FileModificationTimeTest {
   public static void test(String type, File file) {
       long t = file.lastModified();
       System.out.println("The following " + type + " called " + file.getPath() +
            (t == 0 ? " does not exist." : " was modified at " + new Date(t).toString() )
       );
       System.out.println("The following " + type + " called " + file.getPath() + 
            (!file.setLastModified(System.currentTimeMillis()) ? " does not exist." : " was modified to current time." )
       );
       System.out.println("The following " + type + " called " + file.getPath() + 
            (!file.setLastModified(t) ? " does not exist." : " was modified to previous time." )
       );
   }
   public static void main(String args[]) {
       test("file", new File("output.txt"));
       test("directory", new File("docs"));
   }
}
Task: File modification time


C++: #include <boost/filesystem/operations.hpp>
#include <ctime>
#include <iostream>

int main( int argc , char *argv[ ] ) {
   if ( argc != 2 ) {
      std::cerr << "Error! Syntax: moditime <filename>!\n" ;
      return 1 ;
   }
   boost::filesystem::path p( argv[ 1 ] ) ;
   if ( boost::filesystem::exists( p ) ) {
      std::time_t t = boost::filesystem::last_write_time( p ) ;
      std::cout << "On " << std::ctime( &t ) << " the file " << argv[ 1 ] 
	 << " was modified the last time!\n" ;
      std::cout << "Setting the modification time to now:\n" ;
      std::time_t n = std::time( 0 ) ;
      boost::filesystem::last_write_time( p , n ) ; 
      t = boost::filesystem::last_write_time( p ) ;
      std::cout << "Now the modification time is " << std::ctime( &t ) << std::endl ;
      return 0 ;
   } else {
      std::cout << "Could not find file " << argv[ 1 ] << '\n' ;
      return 2 ;
   }
}






Python: import os


modtime = os.path.getmtime('filename')


os.utime('path', (actime, mtime))


os.utime('path', (os.path.getatime('path'), mtime))


os.utime('path', None)
Task: File modification time

C: #include <sys/stat.h>
#include <stdio.h>
#include <time.h>
#include <utime.h>

const char *filename = "input.txt";

int main() {
  struct stat foo;
  time_t mtime;
  struct utimbuf new_times;

  if (stat(filename, &foo) < 0) {
    perror(filename);
    return 1;
  }
  mtime = foo.st_mtime; 

  new_times.actime = foo.st_atime; 
  new_times.modtime = time(NULL);    
  if (utime(filename, &new_times) < 0) {
    perror(filename);
    return 1;
  }

  return 0;
}






PHP: <?php
$filename = 'input.txt';

$mtime = filemtime($filename); // seconds since the epoch

touch($filename,
      time(), // set mtime to current time
      fileatime($filename)); // keep atime unchanged
?>
Task: File modification time



C#: using System;
using System.IO;

Console.WriteLine(File.GetLastWriteTime("file.txt"));
File.SetLastWriteTime("file.txt", DateTime.Now);




PHP: <?php
$filename = 'input.txt';

$mtime = filemtime($filename); // seconds since the epoch

touch($filename,
      time(), // set mtime to current time
      fileatime($filename)); // keep atime unchanged
?>
Task: File modification time


C++: #include <boost/filesystem/operations.hpp>
#include <ctime>
#include <iostream>

int main( int argc , char *argv[ ] ) {
   if ( argc != 2 ) {
      std::cerr << "Error! Syntax: moditime <filename>!\n" ;
      return 1 ;
   }
   boost::filesystem::path p( argv[ 1 ] ) ;
   if ( boost::filesystem::exists( p ) ) {
      std::time_t t = boost::filesystem::last_write_time( p ) ;
      std::cout << "On " << std::ctime( &t ) << " the file " << argv[ 1 ] 
	 << " was modified the last time!\n" ;
      std::cout << "Setting the modification time to now:\n" ;
      std::time_t n = std::time( 0 ) ;
      boost::filesystem::last_write_time( p , n ) ; 
      t = boost::filesystem::last_write_time( p ) ;
      std::cout << "Now the modification time is " << std::ctime( &t ) << std::endl ;
      return 0 ;
   } else {
      std::cout << "Could not find file " << argv[ 1 ] << '\n' ;
      return 2 ;
   }
}





PHP: <?php
$filename = 'input.txt';

$mtime = filemtime($filename); // seconds since the epoch

touch($filename,
      time(), // set mtime to current time
      fileatime($filename)); // keep atime unchanged
?>
Task: File modification time




Go: package main

import (
    "fmt"
    "os"
    "syscall"
    "time"
)

var filename = "input.txt"

func main() {
    foo, err := os.Stat(filename)
    if err != nil {
        fmt.Println(err)
        return
    }
    fmt.Println("mod time was:", foo.ModTime())
    mtime := time.Now()
    atime := mtime 
    
    if ss, ok := foo.Sys().(*syscall.Stat_t); ok {
        atime = time.Unix(ss.Atim.Sec, ss.Atim.Nsec)
    }
    os.Chtimes(filename, atime, mtime)
    fmt.Println("mod time now:", mtime)
}



PHP: <?php
$filename = 'input.txt';

$mtime = filemtime($filename); // seconds since the epoch

touch($filename,
      time(), // set mtime to current time
      fileatime($filename)); // keep atime unchanged
?>
Task: File modification time





Java: import java.io.File;
import java.util.Date;
public class FileModificationTimeTest {
   public static void test(String type, File file) {
       long t = file.lastModified();
       System.out.println("The following " + type + " called " + file.getPath() +
            (t == 0 ? " does not exist." : " was modified at " + new Date(t).toString() )
       );
       System.out.println("The following " + type + " called " + file.getPath() + 
            (!file.setLastModified(System.currentTimeMillis()) ? " does not exist." : " was modified to current time." )
       );
       System.out.println("The following " + type + " called " + file.getPath() + 
            (!file.setLastModified(t) ? " does not exist." : " was modified to previous time." )
       );
   }
   public static void main(String args[]) {
       test("file", new File("output.txt"));
       test("directory", new File("docs"));
   }
}


PHP: <?php
$filename = 'input.txt';

$mtime = filemtime($filename); // seconds since the epoch

touch($filename,
      time(), // set mtime to current time
      fileatime($filename)); // keep atime unchanged
?>
Task: File modification time






PHP: <?php
$filename = 'input.txt';

$mtime = filemtime($filename); // seconds since the epoch

touch($filename,
      time(), // set mtime to current time
      fileatime($filename)); // keep atime unchanged
?>


Python: import os


modtime = os.path.getmtime('filename')


os.utime('path', (actime, mtime))


os.utime('path', (os.path.getatime('path'), mtime))


os.utime('path', None)
Task: File modification time






PHP: <?php
$filename = 'input.txt';

$mtime = filemtime($filename); // seconds since the epoch

touch($filename,
      time(), // set mtime to current time
      fileatime($filename)); // keep atime unchanged
?>



VB: Dim file As New IO.FileInfo("test.txt")


Dim createTime = file.CreationTime
file.CreationTime = createTime.AddHours(1)


Dim writeTime = file.LastWriteTime
file.LastWriteTime = writeTime.AddHours(1)
 

Dim accessTime = file.LastAccessTime
file.LastAccessTime = accessTime.AddHours(1)
Task: Polynomial regression

C: #ifndef _POLIFITGSL_H
#define _POLIFITGSL_H
#include <gsl/gsl_multifit.h>
#include <stdbool.h>
#include <math.h>
bool polynomialfit(int obs, int degree, 
		   double *dx, double *dy, double *store); 
#endif



C#:         public static double[] Polyfit(double[] x, double[] y, int degree)
        {
            
            var v = new DenseMatrix(x.Length, degree + 1);
            for (int i = 0; i < v.RowCount; i++)
                for (int j = 0; j <= degree; j++) v[i, j] = Math.Pow(x[i], j);
            var yv = new DenseVector(y).ToColumnMatrix();
            QR<double> qr = v.QR();
            
            
            var r = qr.R.SubMatrix(0, degree + 1, 0, degree + 1);
            var q = v.Multiply(r.Inverse());
            var p = r.Inverse().Multiply(q.TransposeThisAndMultiply(yv));
            return p.Column(0).ToArray();
        }