Skip to content

Instantly share code, notes, and snippets.

View cdsousa's full-sized avatar

Cristóvão Duarte Sousa cdsousa

View GitHub Profile
@cdsousa
cdsousa / Fast CSE.ipynb
Last active December 19, 2015 16:49
SymPy Common Subexpression Elimination (CSE) Implementation Comparison Example
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@cdsousa
cdsousa / latex.xml
Created September 2, 2013 18:56
KDE Kate / Kateparts / Kile syntax highlighting XML for LaTeX syntax with added highlighting of Python code within PythonTeX environments.
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE language SYSTEM "language.dtd">
<language name="LaTeX" version="1.53" section="Markup" kateversion="2.3" priority="10" extensions="*.tex;*.ltx;*.dtx;*.sty;*.cls;*.bbx;*.cbx;*.lbx;*.tikz" mimetype="text/x-tex" casesensitive="1" author="Jeroen Wijnhout (Jeroen.Wijnhout@kdemail.net)+Holger Danielsson (holger.danielsson@versanet.de)+Michel Ludwig (michel.ludwig@kdemail.net)+Thomas Braun (thomas.braun@virtuell-zuhause.de)" license="LGPL" >
<highlighting>
<contexts>
<!-- Normal text -->
<context name="Normal Text" attribute="Normal Text" lineEndContext="#stay">
<RegExpr String="\\begin(?=[^a-zA-Z])" attribute="Structure" context="FindBeginEnvironment" beginRegion="block" />
<RegExpr String="\\end(?=[^a-zA-Z])" attribute="Structure" context="FindEndEnvironment" />
<RegExpr String="\\(cite|citet|citep|parencite|autocite|Autocite|citetitle)\*(?=[^a-zA-Z])" attribute="Structure" context="Label"/>
@cdsousa
cdsousa / mat_pow_int.jl
Last active August 29, 2015 13:56
Julia custom element-wise integer power of matrices
import Base.(.^)
function .^{T<:FloatingPoint, N}(A::Array{T, N}, x::Integer)
if abs(x) > 42 # the "Answer to the Ultimate Question of Life, the Universe, and Everything"
A.^float(x)
elseif x > 1
B = similar(A)
@inbounds for i in 1:length(A)
B[i] = A[i]
for k in 1:x-1 B[i] *= A[i] end
@cdsousa
cdsousa / SymPyBotics - Coriolis matrix.ipynb
Last active August 29, 2015 14:02
SymPyBotics - Coriolis matrix
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@cdsousa
cdsousa / fsa_literal_macros.jl
Created August 27, 2015 11:38
Experiments with literal vectors and matrices for FixedSizeArrays.jl
using FixedSizeArrays: Mat, FixedVector
immutable Vec{N, T} <: FixedVector{N, T}; _::NTuple{N, T}; end
macro fsa(expr)
if expr.head == :vect
Expr(:call, :Vec, expr.args...)
elseif expr.head == :hcat
Expr(:call, :Mat, [Expr(:tuple, a) for a in expr.args]...)
elseif expr.head == :vcat
if isa(expr.args[1], Expr) && expr.args[1].head == :row
cmake_minimum_required(VERSION 2.6)
project(subclassdispatchtests)
set(CMAKE_BUILD_TYPE Release)
add_definitions(-std=c++11)
add_executable(subclassdispatchtests subclassdispatchtests.cpp)

Here's the canonical TOML example from the TOML README, and a YAML version of the same. Which looks nicer?

title = "TOML Example"

[owner]

#include <atomic>
#include <chrono>
#include <condition_variable>
#include <deque>
#include <future>
#include <iostream>
#include <mutex>
#include <thread>
#include <vector>
module OpenCV
export CvCapture, release, grabFrame, retrieveFrameIplImage, retrieveFrame, namedWindow, showImage, waitKey, destroyAllWindows
import Images
struct CvCapture
cvCapturePtr::Ptr{Cvoid}
sizes::Vector{Cint}
function CvCapture(device::Int = 0)
ptr = ccall((:cvCreateCameraCapture, "libopencv_highgui"), Ptr{Cvoid}, (Cint,), device)
###### test 1
function gamblers_falacy_1(n)
h,t = 0,0; c=0; r=0
for i=1:n
p = t>h ? :h : (h>t ? :t : nothing)
o = rand((:h,:t))