Posts

Upgrade Deno

Upgrading Deno is incredibly easy, with the deno upgrade command. You can also downgrade or upgrade to a dev channel just as easily. You can access the version programatically with Deno.version . View code on GitHub

C# Top level statements

Image
In the newest version of C#, you can have top-level statements instead of putting your entry point in a "static void Main" method. This saves you a couple of indents for your application's starting point, which doesn't really belong in a class in the first place. The compiler magically puts it in a special class and method, but you don't have to worry about that. View code on GitHub

SQLite In-Memory Database

Image
SQLite has an option for running completely in-memory, rather than using a local file on disk. This may be perfect for doing one-time data manipulation or other short-term tasks. Just use :memory: instead of the database filename, and you'll get the in-memory database. Or use an empty string, to use memory only, but a temporary file on disk if memory starts to run low. View code on GitHub

JavaScript splice, slice, shift, pop

Image
These four functions are commonly used to copy or modify arrays in JavaScript. I generally have the signatures printed as a cheat sheet since I can never keep them all straight. splice slice shift pop View code on GitHub

Modify web.config appsettings value

var config = WebConfigurationManager . OpenWebConfiguration ( " ~ " ) ; var section = ( AppSettingsSection ) config . GetSection ( " appSettings " ) ; section . Settings [ " something " ] . Value = " newValue " ; config . Save ( ) ;

NodeJS read/write text files

" use strict " ; ( function ( ) { var fs = require ( " fs " ) ; var readline = require ( " readline " ) ; fs . readFile ( " input.json " , function ( error , data ) { var obj = JSON . parse ( data ) ; fs . writeFile ( " output.json " , JSON . stringify ( obj ) , function ( err ) { if ( err ) { console . log ( " Error: " + err ) ; } else { console . log ( " Saved " ) ; } } ) ; } ) ; ( function ( ) { var outputStream = fs . createWriteStream ( " output.txt " ) ; var lineReader = readline . createInterface ( { input : fs . createReadStream ( " input.txt " ) } ) ; lineReader . on ( " line " , function ( line ) { console . log ( " Line: " + l

NodeJS Read/Write Files

const fs = require ( " fs " ) ; const readline = require ( " readline " ) ; // Read full file fs . readFile ( " myfile.txt " , { encoding : " utf-8 " } , ( err , data ) = > { console . log ( " Full file contents: " ) ; console . log ( data ) ; console . log ( " =================== " ) ; } ) ; // Read file line-by-line var lineReader = readline . createInterface ( { input : fs . createReadStream ( " myfile.txt " ) } ) ; lineReader . on ( " line " , line = > { console . log ( ` Line: ${ line } ` ) ; } ) ; lineReader . on ( " close " , ( ) = > console . log ( " DONE " ) ) ; // Write full file fs . writeFile ( " myfile.txt " , " some file contents " , err = > { if ( err ) console . error ( err ) ; } ) ; // Write file line-by-line var outputStream = fs . createWriteStream ( " myfil