Skip to content

Instantly share code, notes, and snippets.

@ducngtuan
ducngtuan / rename.js
Created May 4, 2018 22:14
Script to rename files based on regex pattern in javascript
const fs = require('fs'),
path = require('path'),
dir = '~/Downloads',
match = /.*_(\w+\.part\d+.rar)/ // change this to whatever pattern needed
files = fs.readdirSync(dir)
files.filter(f => f.match(match)).forEach(f => {
const fpath = path.join(dir, f),
newfpath = path.join(dir, f.replace(match, (m, p1) => p1))
fs.renameSync(fpath, newfpath)
@ducngtuan
ducngtuan / Vagrantfile
Last active October 25, 2023 07:33
Vagrantfile Setup for PHP 5.6
# -*- mode: ruby -*-
# vi: set ft=ruby :
Vagrant.configure("2") do |config|
config.vm.box = "ubuntu/trusty64"
# Create a forwarded port mapping which allows access to a specific port
# within the machine from a port on the host machine. In the example below,
# accessing "localhost:8080" will access port 80 on the guest machine.
# config.vm.network "forwarded_port", guest: 80, host: 8080
<ul>
<li ngRepeat="exercise in exercises | orderBy: exerciseOrder">
{{exercise.title}}
</li>
</ul>
@ducngtuan
ducngtuan / Graph.scala
Last active July 9, 2020 09:43
Solution for the 2nd HW of C++ for C Programmer on Coursera: "Implement a Monte Carlo simulation that calculates the average shortest path in a graph. The graph can be generated using a pseudo-random number generator to produce edges and their costs. The shortest path algorithm will be Dijkstra’s."
class Graph(val V: Int) {
private var e = 0;
private val adj = Array.fill[Double](V * V)(0)
def E = e;
def apply(x: Int) = for (y <- 0 until V if isAdjacent(x, y)) yield y
def apply(x: Int, y: Int) = adj(indexFor(x, y))
@ducngtuan
ducngtuan / Rectangle.java
Last active December 15, 2015 02:59
Example Rectangle class with unify, intersection, contains(Point) methods.
import java.util.Scanner;
public class Rectangle {
public static class Point {
public final float x, y;
public final static Point ORIGIN = new Point(0, 0);
public Point(float x, float y) {
@ducngtuan
ducngtuan / dict.cpp
Created December 18, 2012 23:11
Simple hash table implemented in C++ for string/string key-value pair. DictADT can have duplicated keys. Not optimized for speed, only for demonstration.
#include <iostream>
#include <string>
#include <queue>
using namespace std;
class MapADT {
public:
MapADT();
MapADT(string filename);