Skip to content

Instantly share code, notes, and snippets.

Avatar
🏠
Working from home

Indy M. Indy9000

🏠
Working from home
View GitHub Profile
View 1. FreeAgentCore.fs
#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 Jun 19, 2015
fsharp bootstrap script
View app.fsx
// 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()
View read-streaming-response.fsx
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
View img2ascii.fsx
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 Dec 26, 2015
Create a Streaming Request
View twitter-streaming-oauth.fsx
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 Feb 18, 2016 — forked from XVilka/TrueColour.md
True Colour (16 million colours) support in various terminal applications and terminals
View TrueColour.md

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"
View invert-bin-tree.cs
/*********
* 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 Sep 10, 2016
Exploration of fast convergence of Genetic Algorithms
View weasels.m
%% 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 Jan 24, 2017
CSV splitter for lines with escaped delimeters
View SplitCSV.fsx
(***
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 Feb 6, 2017
Extract longest palindrome from a string of letters
View longest-palindome.cc
#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;