Skip to content

Instantly share code, notes, and snippets.

dashboard "Food":
- h1 text: Food
- h2 text: By caloric content
- 3 columns:
- rows:
- h3 text: Bananas
- pie chart: {
"columns": [
["Protein", 5], ["Sugar", 10], ["Other carbs", 40], ["Fat", 1]
]
dashboard "Food":
- h1 text: Food
- h2 text: By caloric content
- 3 columns:
- rows:
- h3 text: Bananas
- pie chart: {
"columns": [
["Protein", 5], ["Sugar", 10], ["Other carbs", 40], ["Fat", 1]
]
@swuecho
swuecho / playground.rs
Created December 14, 2017 17:22 — forked from anonymous/playground.rs
Rust code shared from the playground
use std::str::FromStr;
fn main () {
let mut input = "15 Bear".split(' ');
// Need to pull the number and parse it.
let number = input.next()
// Process Option<&'static str> to Option<int>
.and_then(|x| i32::from_str(x).ok() )
.expect("Was not provided a valid number.");
// The next token is our animal.
@swuecho
swuecho / playground.rs
Created December 14, 2017 17:17 — forked from anonymous/playground.rs
Rust code shared from the playground
fn main () {
let number: f64 = 20.;
// Perform a pipeline of options.
let result = Some(number)
.map(inverse) // Described below.
.map(double)
.map(inverse)
.and_then(log) // Described below.
.map(square)
.and_then(sqrt);
Prelude> (fmap . const) 1 [1..5]
[1,1,1,1,1]
Prelude> fmap . const 1 [1..5]
<interactive>:29:1: error:
• Non type-variable argument in the constraint: Num (a1 -> a -> b)
(Use FlexibleContexts to permit this)
• When checking the inferred type
it :: forall b a (f :: * -> *) a1.
(Num (a1 -> a -> b), Functor f) =>
@swuecho
swuecho / pet-snippet.toml
Last active March 13, 2017 21:14
description
[[snippets]]
description = "list all files "
command = "ls -lah"
@swuecho
swuecho / gist:c0e9394b183edf120362390b6f4b808f
Created March 9, 2017 00:56 — forked from aidanhs/gist:5ac9088ca0f6bdd4a370
Rust binary tree worked example

% Let's build a binary tree!

Let's build a binary tree of strings in Rust. To recap, each node in a binary tree:

  1. must have a value
  2. may or may not have left and/or right children

So we can describe a single node like this:

#!/usr/local/bin/perl
package MyAnalyzer {
use v5.10;
use base qw( Lucy::Analysis::Analyzer );
sub new {
my $self = shift->SUPER::new;
return $self;
}
https://godbolt.org/g/cmHlPR
import subprocess
def system(cmd):
"""
Invoke a shell command.
:returns: A tuple of output, err message and return code
"""
ret = subprocess.Popen(cmd, shell=True, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE, close_fds=True)
out, err = ret.communicate()
return out, err, ret.returncode