Skip to content

Instantly share code, notes, and snippets.

View OnorioCatenacci's full-sized avatar

Onorio Catenacci OnorioCatenacci

View GitHub Profile
@OnorioCatenacci
OnorioCatenacci / stack.ex
Last active August 29, 2015 14:00
A Naive Implementation Of A Stack
defmodule Stack do
defstruct name: "", value: 0
def init() do
_s = []
end
def push(name, value, s) do
s_new = [%Stack{name: name, value: value}, s]
{:ok,s_new}
@OnorioCatenacci
OnorioCatenacci / WinClip.ex
Created August 1, 2014 19:27
How To Write Data To Windows Clipboard
defmodule WinClip do
def write_to_clipboard(string_to_write) do
p = Port.open({:spawn,"clip"},[:stderr_to_stdout, :stream, :binary, :exit_status])
Port.command(p,string_to_write)
Port.close(p)
end
end
Good Fonts:
Font Squirrel: http://www.fontsquirrel.com/
Urban Fonts: http://www.urbanfonts.com/
Google Web Fonts: http://www.google.com/fonts/
Color Schemes:
Colour Lovers: http://www.colourlovers.com/
Color Scheme Designer: http://colorschemedesigner.com/
Image Color Picker: http://imagecolorpicker.com/
#Two small, quick date utility functions. Convert a wxDateTime (from wxErlang) to a YYYYMMDD string. NB: assumes year is post 1000 CE.
defp wxDatetime_to_string({{year,month,day},{_hour,_minute,_second}}), do: "#{year}#{zero_padding(month,2)}#{zero_padding(day,2)}"
#Pad a string out with a specified number of leading zeroes.
defp zero_padding(string,len), do: String.rjust(to_string(string), len, ?0)
@OnorioCatenacci
OnorioCatenacci / SmallJSONDemo.fs
Created July 16, 2010 00:42
F# fragment for JSON Serialize/Deserialize
(* Borrowed very liberally from
https://blogs.msdn.com/b/jomo_fisher/archive/2010/03/06/neat-samples-f-freebase-and-dgml.aspx
and
http://cs.hubfs.net/forums/permalink/11096/11096/ShowThread.aspx#11096
Many thanks to both those posters for giving me 99% of the starting code
@OnorioCatenacci
OnorioCatenacci / ReturnRandomString.fs
Created December 9, 2010 12:58
Return a random string from an array of strings
// Copy/paste this into the FSI to see what it does.
open System
let a = [|"a";"b";"c";"d"|]
let randstring (arr:string[]) =
let r = new Random()
arr.[r.Next(arr.Length)]
let resultstring = randstring a;;
@OnorioCatenacci
OnorioCatenacci / UnitsOfMeasure2.fs
Created August 1, 2011 15:51
F# Units of Measure and Interfaces
module measures
type ILinear =
interface
end
[<Measure>] type inch =
@OnorioCatenacci
OnorioCatenacci / FilterTextFile.fsx
Created October 24, 2011 01:19
A quick and dirty F# Shell Script to filter a text file for all lines which match a certain string
(*
* Filter a specified file into a second file
* Onorio Catenacci
* 21 October 2011
*)
#r "System.dll"
open System.IO
//Remember:
@OnorioCatenacci
OnorioCatenacci / StartST2.fsx
Created February 29, 2012 16:18
Start Sublime Text 2 With Git Plugin
#nowarn "62"
//Note this is running on Win7 x64 but git is 32 bit.
let pathEnvVar = "Path"
let gitBin = @"\Program Files (x86)\Git\bin"
let st2Bin = @"\Program Files\Sublime Text 2"
let currentPath = System.Environment.GetEnvironmentVariable(pathEnvVar)
let modifiedPath = gitBin ^ ";" ^ st2Bin ^ ";" ^ currentPath
System.Environment.SetEnvironmentVariable (pathEnvVar,modifiedPath)
@OnorioCatenacci
OnorioCatenacci / githelpers.ps1
Created April 8, 2013 16:00
Everyday Git Aliases For Powershell (Github For Windows)
#Adjust these values for your own installation.
Set-Variable -Name defaultDirectory -option Readonly -value "c:/mydev"
Set-Variable -Name defaultRepository -option Readonly -value "myrepo"
Set-Variable -Name defaultBranch -option Readonly -value "workbranch"
#Per "Everyday git-aliases", do a rebase as opposed to a merge
function gpurr($repository=$defaultRepository, $branch=$defaultBranch)
{
& 'git' pull --rebase $repository $branch
}