Skip to content

Instantly share code, notes, and snippets.

Tuomas Hietanen Thorium

Block or report user

Report or block Thorium

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
@Thorium
Thorium / gist:1972225
Created Mar 4, 2012
Convert an object to json, and json to object
View gist:1972225
#r "System.Runtime.Serialization" // for interactive
// Reference to assembly System.Runtime.Serialization and System.Xml
open System.IO
open System.Runtime.Serialization.Json
open System.Xml
open System.Text
/// Object to Json
let internal json<'t> (myObj:'t) =
@Thorium
Thorium / Rijndael.fs
Created Mar 4, 2012
Decrypting a Rijndael string
View Rijndael.fs
open System.IO
open System.Security.Cryptography
open System.Text
open System.Diagnostics.Contracts
let DeCryptStringWith (crypted:string) (key:string) (iv:string) =
let enc = new ASCIIEncoding()
let algo = Rijndael.Create()
if(crypted.Length < 5) then
failwith "Crypted string length has to be over 5 chars."
@Thorium
Thorium / gist:1972308
Created Mar 4, 2012
Get Stock Quote Data and Historical Stock Prices from Yahoo Finance
View gist:1972308
open System
open System.IO
open System.Xml
open System.Text
open System.Net
open System.Globalization
let makeUrl symbol (dfrom:DateTime) (dto:DateTime) =
//Uses the not-so-known chart-data:
let monthfix (d:DateTime)= (d.Month-1).ToString()
@Thorium
Thorium / gist:1972331
Created Mar 4, 2012
Getting a key from Windows registry
View gist:1972331
let REGISTRYSOFTWARE = "Software";
let REGISTRYMYPATH = "MySoftware";
let internal GetRegistryValue key =
use path1 = Microsoft.Win32.Registry.LocalMachine.OpenSubKey(REGISTRYSOFTWARE)
match path1 with
| null -> failwith("Access failed to registry: hklm\\"+REGISTRYSOFTWARE)
| keyhklmsw ->
use path2 = keyhklmsw.OpenSubKey(REGISTRYMYPATH)
match path2 with
@Thorium
Thorium / gist:1972345
Created Mar 4, 2012
Function to get all possible combinations
View gist:1972345
//See examples:
//Input: ["a";"b"]
//Output: ["a"; "b"; "ab"]
//Input: ["a";"b";"c";"d"]
//Output: ["a"; "b"; "c"; "d"; "ab"; "ac"; "ad"; "bc"; "bd"; "cd"; "bcd"; "abc"; "abd"; "acd"; "abcd"]
//Input: [1;2;5]
//Output: [1; 2; 5; 3; 6; 7; 8]
@Thorium
Thorium / gist:1972349
Created Mar 4, 2012
Timestamp with timezone (YYYYMMDDhhmmssffff+zzzz)
View gist:1972349
let myTimeStamp =
let zone = System.TimeZone.CurrentTimeZone.GetUtcOffset System.DateTime.Now
let prefix = match (zone<System.TimeSpan.Zero) with | true -> "-" | _ -> "+"
System.DateTime.UtcNow.ToString("yyyyMMddHHmmssffff") + prefix + zone.ToString("hhss");
@Thorium
Thorium / gist:1972350
Created Mar 4, 2012
SHA512 hash code from a string
View gist:1972350
let generateHash text =
let getbytes : (string->byte[]) = System.Text.Encoding.UTF8.GetBytes
use algorithm = new System.Security.Cryptography.SHA512Managed()
text |> (getbytes >> algorithm.ComputeHash >> System.Convert.ToBase64String)
//use example:
let id, time, secretkey = "1", System.DateTime.Now.ToString("yyyyMMddhhmmss"), "mysecret"
generateHash (secretkey + id + time)
@Thorium
Thorium / MainPage.xaml.cs
Created Mar 4, 2012
Simple F# ViewModel for Silverlight MVVM
View MainPage.xaml.cs
//View codebehind
using System.Windows.Controls;
namespace HelloApp
{
public partial class MainPage : UserControl
{
public MainPage()
{
// Required to initialize variables
@Thorium
Thorium / gist:1972368
Created Mar 4, 2012
Silverlight asynchronous WebService call with UI-thread syncronization dispatcher
View gist:1972368
//#r "System.Runtime.Serialization"
//#r "FSharp.PowerPack"
open Microsoft.FSharp.Control.WebExtensions
open System
open System.Runtime.Serialization
open System.Runtime.Serialization.Json
open System.Net
open System.IO
@Thorium
Thorium / QuickInfo.fs
Created Mar 4, 2012
csproj-file parsing with Linq2Xml, two examples
View QuickInfo.fs
//#r "System.Xml.dll" //for scripts or interactive
//#r "System.Xml.Linq.dll"
open System
open System.Xml.Linq
open System.IO
let getFiles = Directory.GetFiles("c:\\projects\\", "*.csproj", SearchOption.AllDirectories)
|> Array.toSeq
let getProjectInfo (fname:string) =
You can’t perform that action at this time.