Skip to content

Instantly share code, notes, and snippets.

View vermorel's full-sized avatar

Joannes Vermorel vermorel

View GitHub Profile
# Replace commas by dots in a very large file (full streaming)
$infile = ls .\MyFile.csv
$outfile = $infile.DirectoryName + "\MyFile.csv.out"
$reader = [System.IO.File]::OpenText($infile.FullName)
$writer = [System.IO.StreamWriter] $outfile
try {
for(;;) {
$line = $reader.ReadLine()
if ($line -eq $null) { break }
# process the line
@vermorel
vermorel / sample-content.ps1
Created March 27, 2014 09:51
Create a sample large flat files (keeping only 1 line out of N)
# Sample-Content
# By Joannes Vermorel, 2014
# Keep only 1 line out of N of a flat file
# Usage: sample-content .\myfile.csv 100
function Sample-Content()
{
param
(
[string]$path = $null,
@vermorel
vermorel / Program.cs
Created August 18, 2011 16:52
Email address extraction from Relenta CSV export
// The CSV file produced by Relenta while exporting contact is somewhat messy.
// Using this tiny app to extract the first email address of each contact.
using System;
using System.IO;
namespace ConsoleTest
{
class Program
{
@vermorel
vermorel / measure-loc.ps1
Created November 24, 2011 17:45
measure-loc, PowerShell function, Recurse directories and compute the number of C# lines
# Measure-Loc
# By Joannes Vermorel, 2010
# Recurse directories and compute the number of C# lines
# Usage: measure-loc
function Measure-Loc
{
param(
)
@vermorel
vermorel / delete-svn.cmd
Created February 7, 2012 09:11
Delete recursively all .svn folders from the Windows command-line
for /f "tokens=* delims=" %%i in ('dir /s /b /a:d *.svn') do (
rd /s /q "%%i"
)
@vermorel
vermorel / search-lokadwiki.ps1
Last active October 6, 2015 18:43
Prints the page names of the pages on Lokad.com that contains a specific string in their original wiki markup
#----------------------------------------------------------------
# function Search-LokadWiki
# By Joannes Vermorel, Oct 2015, Lokad
#
# Print all the wiki page names that contains a specific string
# in their wiki code.
#----------------------------------------------------------------
function Search-LokadWiki()
{
param
@vermorel
vermorel / crossjoin-csv.ps1
Created December 11, 2015 08:48
CrossJoin-Csv, cartesian product on flat files
# Cross-Join between two flat files
# By Joannes Vermorel, 2015-12-11
#
# Syntax:
# Crossjoin-Csv .\sample.csv .\sample.csv "Name"
function Crossjoin-Csv
{
param
(
@vermorel
vermorel / FlatSampling.cs
Last active December 19, 2015 19:48
Tiny stand-alone flat file sampling utility.
using System;
using System.IO;
using System.IO.Compression;
using System.Text;
namespace Loader
{
class FlatSampling
{
static void Main(string[] args)
@vermorel
vermorel / BasicAuthAttribute.cs
Created October 23, 2013 07:02
Basic Authentication in ASP.NET MVC4
using System;
using System.Linq;
using System.Net;
using System.Security.Principal;
using System.Text;
using System.Web;
using System.Web.Mvc;
namespace ClientUI
{
@vermorel
vermorel / convert-daily.ps1
Last active April 4, 2016 18:23
Random expansion of monthly data into daily data
# Random expansion of monthly data into daily data
# Syntax: convert-daily "c:\LokadData\foo.tsv"
# Expected columns are Id, Date, Quantity
# By Joannes Vermorel, April 2016
function convert-daily
{
param
(
[string] $file