Skip to content

Instantly share code, notes, and snippets.

View trickster's full-sized avatar
🎯
Focusing

Sivaram Konanki trickster

🎯
Focusing
  • Tokyo
  • 02:18 (UTC +09:00)
View GitHub Profile
@trickster
trickster / strrep.rb
Created August 26, 2012 11:48
THis is a public gist
class Array
def check_all_odd
self.each do |i|
if i.even?
return false
else
next
end
end
return true

This is temp file to share via gist.

@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 / case.nim
Created March 5, 2018 15:10
Nim cases
case 'h':
of 'a', 'e', 'i', 'o', 'u':
echo "Vowel"
of '\127'..'\255':
echo "Unknown"
else:
echo "Consonant"
proc positiveOrNegative(num: int): string =
result = case num:
@trickster
trickster / control.nim
Created March 5, 2018 15:18
control flow in Nim
import strutils, random
randomize()
let answer = rand(10)
while true:
echo "Guess the number?"
let guess = parseInt(stdin.readLine)
if guess < answer:
echo "Less than answer"
@trickster
trickster / parallel.nim
Created March 11, 2018 06:24
Parallel stuff in Nim
import threadpool, tables, strutils
const
filesArray = ["data1.txt", "data2.txt", "data3.txt"]
proc countWords2(filename: string): CountTableRef[string] =
result = newCountTable[string]()
for word in readFile(filename).splitWhitespace():
result.inc word
@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 ([email protected], @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
@trickster
trickster / regex.p6
Created March 16, 2018 08:42
Regex perl
# p6
$_ = 'my123123 2replacements 7123';
s/\d+//; # extract the first occurance of the numbers
# `m` is for matching
if 'properly' ~~ m/ perl / {
say "properly contains 'perl'"
}
(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)