Skip to content

Instantly share code, notes, and snippets.

View trickster's full-sized avatar
🎯
Focusing

Sivaram Konanki trickster

🎯
Focusing
View GitHub Profile
@trickster
trickster / rust-python-cffi.md
Created February 2, 2018 07:33 — forked from seanjensengrey/rust-python-cffi.md
Calling Rust from Python/PyPy using CFFI (C Foreign Function Interface)

This is a small demo of how to create a library in Rust and call it from Python (both CPython and PyPy) using the CFFI instead of ctypes.

Based on http://harkablog.com/calling-rust-from-c-and-python.html (dead) which used ctypes

CFFI is nice because:

  • Reads C declarations (parses headers)
  • Works in both CPython and PyPy (included with PyPy)
  • Lower call overhead than ctypes
@trickster
trickster / playground.rs
Last active March 3, 2018 04:26 — forked from anonymous/playground.rs
Rust code shared from the playground (Iterators)
/*
Iterators and all functions that operates on iterators, are lazy by default.
Executes on demand.
Here in we have `println` that executes the lazy expression that is `largest`.
*/
fn main() {
let a = [5,2,3,1,5,7,3];
@trickster
trickster / perl-one-liners
Created March 16, 2018 00:49
Perl One-Liners
Useful One-Line Scripts for Perl Dec 03 2013 | version 1.10
-------------------------------- ----------- ------------
Compiled by Peteris Krumins (peter@catonmat.net, @pkrumins on Twitter)
http://www.catonmat.net -- good coders code, great reuse
Latest version of this file is always at:
http://www.catonmat.net/download/perl1line.txt
(require '[clojure.core.async :as a])
(def xform (comp (map inc)
(filter even?)
(dedupe)
(flatmap range)
(partition-all 3)
(partition-by #(< (apply + %) 7))
(flatmap flatten)
(random-sample 1.0)
@trickster
trickster / gist:b0c02e318e38ef93ecbb7a3121cce62f
Created April 4, 2018 08:45 — forked from shriphani/gist:8675874
Racket code for the little schemer
#lang racket
;; Code for the little schemer
(define (atom? x)
(and (not (pair? x))
(not (null? x))))
(define (lat? l)
(cond ((null? l) #t)
@trickster
trickster / wclwn.md
Created April 6, 2018 07:55 — forked from zacharycarter/wclwn.md
Binding to C Libraries with Nim
@trickster
trickster / startup.jl
Last active April 24, 2018 04:54 — forked from MikeInnes/startup.jl
Julia macros (forked)
#=
## Taken from Old Julia documentation.
Escape analysis - (esc(n))
An expression wrapped in this manner is left alone by
the macro expander and simply pasted into the output verbatim.
Therefore it will be resolved in the macro call environment.
An expression wrapped in this manner is left alone by the macro expander
and simply pasted into the output verbatim.
@trickster
trickster / exercise.tour.go
Created April 28, 2018 09:04 — forked from zyxar/exercise.tour.go
tour.golang exercise solutions
/* Exercise: Loops and Functions #43 */
package main
import (
"fmt"
"math"
)
func Sqrt(x float64) float64 {
z := float64(2.)
@trickster
trickster / playground.rs
Created May 20, 2018 05:20 — forked from rust-play/playground.rs
Reference counting
enum List {
Cons(i32, Rc<List>),
Nil,
}
use std::rc::Rc;
use List::{Cons, Nil};
#[allow(unused_variables)]
fn main() {
@trickster
trickster / traits.rs
Last active May 20, 2018 12:19 — forked from rust-play/playground.rs
Traits, trait bounds and lifetimes
// use aggregator::Summary; - to import from the
// other crates
/*
TRAIT BOUNDS
we implemented the Summary trait on the types NewsArticle and Tweet.
We can define a function notify that calls the summarize method
on its parameter item, which is of the generic type T.