Skip to content

Instantly share code, notes, and snippets.

View Indy9000's full-sized avatar
🏠
Working from home

Indy M. Indy9000

🏠
Working from home
View GitHub Profile
#I @"packages"
#r @"Http.Fs\lib\net40\HttpClient.dll"
#r @"FSharp.Data\lib\net40\FSharp.Data.dll"
open HttpClient
open FSharp.Data
module Security =
type RefreshTokenResponse = JsonProvider< """{
"access_token":"ACCESS TOKEN",
@Indy9000
Indy9000 / app.fsx
Created June 19, 2015 21:24
fsharp bootstrap script
// Step 0. Boilerplate to get the paket.exe tool
open System
open System.IO
Environment.CurrentDirectory <- __SOURCE_DIRECTORY__
if not (File.Exists "paket.exe") then
let url = "https://github.com/fsprojects/Paket/releases/download/0.31.5/paket.exe"
use wc = new Net.WebClient()
@Indy9000
Indy9000 / read-streaming-response.fsx
Created December 26, 2015 00:00
Read Twitter Stream
let ReadStreamingResponse (w:WebRequest) =
try
let resp = w.GetResponse() :?> HttpWebResponse
use responseStream = resp.GetResponseStream()
use responseReader = new StreamReader(responseStream, true)
let atEnd = responseReader.EndOfStream
while(not atEnd) do
let line_size = responseReader.ReadLine()
if not (String.IsNullOrEmpty line_size) then
@Indy9000
Indy9000 / img2ascii.fsx
Created December 26, 2015 00:29
image to ascii
let Color2Gray (c:Color) =
//((float)c.R * 0.3) + ((float)c.G * 0.59) + ((float)c.B * 0.11)
((float)c.R * 0.2126) + ((float)c.G * 0.7152) + ((float)c.B * 0.0722)
let Image2Ascii (img:Image) =
let mutable n_h = 60
let mutable n_w = 80
n_h <- (int)((float)img.Height * (float)n_w/(2.1 *(float)img.Width)) //calculate resized height
@Indy9000
Indy9000 / twitter-streaming-oauth.fsx
Last active December 26, 2015 10:05
Create a Streaming Request
let GetUnixEpochTimeStamp =
//test: "1318622958"
let secs = (System.DateTime.UtcNow.Subtract(new DateTime(1970,1,1))).TotalSeconds
Convert.ToInt64(secs).ToString(System.Globalization.CultureInfo.InvariantCulture)
let GetNonce =
//test: let nonce = "kYjzVBB8Y0ZFabxSWbWovY3uYSQ2pTgmZeNu2VS4cg"
Guid.NewGuid().ToString().Replace("-", String.Empty) //32 alphanumeric chars
let EncodeChar (c:char) =
@Indy9000
Indy9000 / TrueColour.md
Created February 18, 2016 17:43 — forked from XVilka/TrueColour.md
True Colour (16 million colours) support in various terminal applications and terminals

Colours in terminal

It's a common confusion about terminal colours... Actually we have this:

  • plain ascii
  • ansi escape codes (16 colour codes with bold/italic and background)
  • 256 colour palette (216 colours + 16 ansi + 24 gray) (colors are 24bit)
  • 24bit true colour ("888" colours (aka 16 milion))
printf "\x1b[${bg};2;${red};${green};${blue}m\n"
/*********
* This Gist was created at CSharpPad.com
* To run this file, open http://csharppad.com/gist/b93b925c378a4ff2a04fa5bc0e218786
**********/
class Node{
public int value;
public Node left;
public Node right;
}
@Indy9000
Indy9000 / weasels.m
Created September 10, 2016 23:04
Exploration of fast convergence of Genetic Algorithms
%% Exploration of fast convergence of Genetic Algorithms
% This matlab script contains the code for the results presented in the
% above paper.
%%
function weasels()
% Test main hypothesis, if crossover speeds up convergence
experiment1()
% Effect of smaller population
experiment2()
% Effect of range of mutation over range of crossover probabilities
@Indy9000
Indy9000 / SplitCSV.fsx
Created January 24, 2017 22:17
CSV splitter for lines with escaped delimeters
(***
Converts a csv line which contain escaped elements delimited by for example ". The elements inside these delimters
can contain a , so a simple line.Split(',') would be incorrect.
example:
converts
val line : string = ""22 Dec 2014",BP,"EXPENSES ","1000.00", , "
to
val toks : string [] = [|"22 Dec 2014"; "BP"; "EXPENSES "; "1000.00"; " "|]
***)
@Indy9000
Indy9000 / longest-palindome.cc
Last active February 6, 2017 23:57
Extract longest palindrome from a string of letters
#include <iostream>
#include <string>
std::string longest_palindrome(const std::string& word){
if(word.size()<3)
return std::string();
std::string longest("");
for(std::size_t i=1;i<word.size()-1;++i){
auto left = i - 1;