Skip to content

Instantly share code, notes, and snippets.

View leotm's full-sized avatar

LeoTM leotm

View GitHub Profile
@leotm
leotm / default_syntax.py
Last active July 9, 2020 18:54
Sublime Text 3 - Set default syntax
# AppData\Roaming\Sublime Text 3\Packages\User\default_syntax.py
import sublime, sublime_plugin
class DefaultSyntaxCommand(sublime_plugin.EventListener):
def on_new(self, view):
# Replace <Language> with desired default language
# Check in AppData\Local\Sublime Text 3\Cache
view.set_syntax_file('Packages/<Language>/<Language>.tmLanguage')
@leotm
leotm / findAndReplace.js
Last active June 13, 2024 11:26
Node.js - Find and Replace file(s)
var glob = require('glob');
var fs = require('fs');
var replace = require('replace');
// Find file(s)
glob('fileName.txt', function(err, files) {
if (err) { throw err; }
files.forEach(function(item, index, array) {
console.log(item + ' found');
@leotm
leotm / delete.js
Last active August 29, 2015 14:25
Node.js - Delete file(s)
var glob = require('glob');
var fs = require('fs');
// Find file(s)
glob('**/fileName.ext', function(err, files) {
if (err) { throw err; }
files.forEach(function(item, index, array) {
console.log(item + ' found');
// Delete file(s)
fs.unlink(item, function(err) {
@leotm
leotm / rename.js
Last active August 29, 2015 14:25
Node.js - Rename file(s)
var glob = require('glob');
var fs = require('fs');
// Find file(s)
glob('fileName.ext', function(err, files) {
if (err) { throw err; }
// Check for file(s)
if (Boolean(files.length)) {
files.forEach(function(item, index, array) {
var newItem = item.replace('regexp', 'replacement');
@leotm
leotm / append.js
Last active August 29, 2015 14:25
Node.js - Append regexp to file(s)
var glob = require('glob');
var fs = require('fs');
// Find file(s)
glob('fileName.ext', function(err, files) {
if (err) { throw err; }
files.forEach(function(item, index, array) {
console.log(item + ' found.');
// Read file(s)
var file = fs.readFileSync(item, 'utf8');
@leotm
leotm / .jscsrc
Last active August 29, 2015 14:26
JSCS - JavaScript Code Style - Rules
{
"jscsVersion": "2.0.0",
"preset": "google",
"fileExtensions": [".js", "jscs"],
"validateQuoteMarks": true,
"requireParenthesesAroundIIFE": true,
"maximumLineLength": 120,
"validateLineBreaks": "LF",
@leotm
leotm / getLinks.js
Last active August 29, 2015 14:26
Get all links from website
@leotm
leotm / getLinks.js
Last active August 29, 2015 14:26
Download all links from website
@leotm
leotm / ovpnAuth.js
Last active July 25, 2018 16:53
Node.js - Add authentication to OpenVPN (.ovpn) files
var fs = require("fs");
var glob = require("glob");
glob('*.ovpn', function (err, files) {
if (err) { throw err; }
files.forEach(function(item,index,array){
// Each .ovpn file will use login.conf containing un and pw
fs.appendFile(item, ' auth-user-pass login.conf', function (err) {});
});
});
@leotm
leotm / ovpnSort.js
Last active February 5, 2016 11:25
Node.js - IPVanish - OpenVPN - Sort .ovpn config files into folders by Country
// This will sort all IPVanish config/.ovpn files (e.g. ipvanish-BE-Brussels-bru-b01.ovpn)
// into respective folders (e.g. ipvanish-BE)
var glob = require('glob');
var fs = require('fs');
glob('*.ovpn', function(err, files) {
if (err) { throw err; }
files.forEach(function(item, index, array) {
// Create the folders