Skip to content

Instantly share code, notes, and snippets.

Giacomo Stelluti Scala gsscoder

Block or report user

Report or block gsscoder

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@gsscoder
gsscoder / myprofile.sh
Last active Nov 16, 2019
Shell customizations
View myprofile.sh
# common aliases
alias ll='ls -lha'
alias la='ls -A'
alias l='ls -CF'
# grep options
export GREP_OPTIONS="--color=always"
export GREP_COLOR="1;35;40"
# editor
@gsscoder
gsscoder / check-term-colors.py
Last active Nov 16, 2019
Checks if terminal supports colors
View check-term-colors.py
def supports_color():
# Ripped from: https://github.com/django/django/blob/master/django/core/management/color.py#L12
plat = sys.platform
supported_platform = plat != 'Pocket PC' and (plat != 'win32' or 'ANSICON' in os.environ)
# isatty is not always implemented, #6223.
is_a_tty = hasattr(sys.stdout, 'isatty') and sys.stdout.isatty()
return supported_platform and is_a_tty
@gsscoder
gsscoder / csv2json_cities.py
Last active Nov 16, 2019
Creates a list of cities in JSON
View csv2json_cities.py
# file URL: https://raw.githubusercontent.com/gsscoder/test-data/master/largest-cities.csv
import csv
import re
cities = []
with open('largest-cities.csv') as f:
reader = csv.DictReader(f, delimiter=',')
for row in reader:
@gsscoder
gsscoder / csv2regex_lang-codes.py
Last active Nov 9, 2019
Script to turn languages code into part of a regex
View csv2regex_lang-codes.py
# file URL: https://raw.githubusercontent.com/gsscoder/test-data/master/language-codes-3b2.csv
buf = ''
with open('language-codes-3b2.csv') as csv:
data = csv.readlines()
for d in data[1:]:
langs = d.split(',')
buf += f'{langs[0].upper()}|{langs[1].upper()}|'
@gsscoder
gsscoder / closure-conf.cs
Last active Nov 7, 2019
Illustrates how to configure an object using closures in C#
View closure-conf.cs
class Program
{
static void Main(string[] args)
{
var obj1 = new ToBeConfigured(with =>
{
with.UseB();
with.SetParam("something");
});
@gsscoder
gsscoder / RenameFixtureMethods.fs
Last active Nov 7, 2019
Simple F# program to rename my C# test fixture methods
View RenameFixtureMethods.fs
(*
Description: Simple program to change naming conventions of my C# test fixtures.
Purpose: Learn F#!
Author: Giacomo Stelluti Scala
Created: 2013-01-28
*)
open System
open System.IO
open System.Globalization
open System.Text
@gsscoder
gsscoder / SimpleCmdLineApp.vb
Last active Nov 7, 2019
Simple Command Line Parser Library Console Application
View SimpleCmdLineApp.vb
' needs CommandLine.dll prior to 1.9.4.91
' for later versions: templates are up to date
Imports CommandLine
Imports CommandLine.Text
Imports System.Reflection
<Assembly: [AssemblyInformationalVersion]("1.0.0.0")>
Friend Class ThisAssembly
Friend Shared Title As String = "VBNetTemplate"
Friend Shared Author As String = "Your Name Here"
Friend Shared Copyright As String = "Copyright (C) 2012 " + Author
View SimpleOwinApp.cs
using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
using System.ComponentModel.Composition;
using System.Threading.Tasks;
using AppFunc = System.Func< // Call
System.Collections.Generic.IDictionary<string, object>, // Environment
System.Threading.Tasks.Task>; // Done
@gsscoder
gsscoder / SurfSample1.cs
Last active Nov 7, 2019
Super-Simple HTTP Server, demonstrates use of https://github.com/gsscoder/surfhttp (work in progress)
View SurfSample1.cs
/*
* Toy HTTP Sample Server
* Giacomo Stelluti Scala (gsscoder@gmail.com)
* Demonstrates use of https://github.com/gsscoder/surfhttp (work in progress).
* How to execute: Copy & paste, then add a reference to Surf.dll.
*/
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
@gsscoder
gsscoder / PeekableStream.cs
Last active Nov 7, 2019
Peekable readonly .NET/C# stream, implemented for https://github.com/gsscoder/httphelpers
View PeekableStream.cs
// PeekableReader is better -> https://gist.github.com/gsscoder/4945440
sealed class PeekableStream : Stream
{
public PeekableStream(Stream stream)
{
_stream = stream;
_peeked = new byte[16];
_peekedLength = 0;
}
You can’t perform that action at this time.