Skip to content

Instantly share code, notes, and snippets.

View sshine's full-sized avatar
🦀

Simon Shine sshine

🦀
View GitHub Profile
use num_traits::{Zero, One};
use std::ops::{AddAssign};
fn enumerate_generic<T>() -> impl Iterator<Item = T>
where
T: Clone + Zero + One + AddAssign,
{
let mut curr = T::zero();
std::iter::repeat_with(move || {
let next = curr.clone();
@sshine
sshine / before.rs
Last active September 26, 2022 22:36
use nom::bytes::complete::*;
use nom::error::ParseError;
use nom::sequence::tuple;
use nom::InputTakeAtPosition;
use nom::{error::VerboseError, IResult};
fn main() {
let a: ParseResult<()> = skip_whitespace(" hello");
println!("Parse result: {:?}", a);
}
@sshine
sshine / CollatzConjecture.hs
Created November 28, 2018 06:17
Benchmarking CollatzConjecture
{-# LANGUAGE BangPatterns #-}
module CollatzConjecture ( collatz
, collatz1
, collatz2
, collatz3
, collatz4
, collatz5
) where
import Data.List (genericLength, elemIndex)
#!/usr/bin/env tclsh
proc sum {k m n e} {
set r 0
for {set k $m} {$k < $n} {incr k} {
set r [expr {$r + [uplevel 1 [list set k $k]; uplevel 1 $e]}]
}
return $r
}
set test [sum k 1 5 {expr {pow($k, 2)}}]
using (WebClient webClient = new WebClient())
{
webClient.Headers.Add("Content-Type", "application/x-www-form-urlencoded");
byte[] request = System.Text.Encoding.UTF8.GetBytes("payload=" + JsonConvert.SerializeObject(message));
byte[] response = webClient.UploadData(this._webHookUri, "POST", request);
}
@sshine
sshine / cata.hs
Last active September 29, 2016 16:09
import Data.Char
import Control.Monad
import Control.Applicative
para :: (a -> b -> [a] -> b) -> b -> [a] -> b
para f e [] = e
para f e (x:xs) = para f (f x e xs) xs
main = do
@sshine
sshine / .ghci
Created September 10, 2015 13:34
let ghciEscape arg = "'" ++ concatMap (\c -> if c == '\'' then "'\"'\"'" else [c]) arg ++ "'"
:def! hoogle return . (":! hoogle --color --count=20 " ++) . ghciEscape
:def! doc return . (":! hoogle --color --info " ++) . ghciEscape
:set prompt "\ESC[1;34m%s\n\ESC[0;34mλ> \ESC[m"
## Ignore Visual Studio temporary files, build results, and
## files generated by popular Visual Studio add-ons.
# User-specific files
*.suo
*.user
*.sln.docstates
# Build results
[Dd]ebug/
{-# LANGUAGE TupleSections #-}
import Data.Char
import Control.Monad
import Control.Applicative hiding (many)
import Text.ParserCombinators.ReadP
import Test.QuickCheck
data Exp = Add Exp Exp
| Sub Exp Exp
@sshine
sshine / gist:fe5ddf9c3763583e0c10
Created January 20, 2015 01:24
I miss monads...
$.ajax({ url: "foo.csv", dataType: "text" })
.done(function(data) {
fetchPostTags(data);
$.ajax({ url: "bar.csv", dataType: "text" })
.done(fetchPostsComments);
.fail(function(failure) {
updateStatus("Failed to load posts-comments.csv");
console.log(failure);
});