Skip to content

Instantly share code, notes, and snippets.

View ydm's full-sized avatar

Йордан Миладинов ydm

  • Sofia, Bulgaria
View GitHub Profile
@ydm
ydm / Coconuts.hs
Last active November 18, 2015 17:01
#!/usr/bin/env runhaskell
check :: Maybe Int -> Maybe Int
check Nothing = Nothing
check (Just x)
| x `mod` 4 == 0 = Just (f x)
| otherwise = Nothing
where f x = 5 * (floor $ (fromIntegral x) / 4) + 1
solution :: Int -> [Maybe Int]
@ydm
ydm / chain.py
Last active March 14, 2016 07:41
Chain functions in Python. It's like Haskell's dot operator, but better. ^_^
import functools
def chain(*fs, reverse=True):
def dec(g):
@functools.wraps(g)
def wrapper(*args, **kwargs):
functions = reversed(fs) if reverse else fs
a = lambda m, f: f(m)
return functools.reduce(a, functions, g(*args, **kwargs))
(defun vray/render-vrscene ()
(interactive)
(let* ((vray "/usr/autodesk/maya2016/vray/bin/vray")
(scene (buffer-file-name))
(cmd (format "%s -sceneFile=%s -imgFile=/tmp/output.png &" vray scene)))
(shell-command cmd)))
@ydm
ydm / printMatrix.mel .c
Last active December 17, 2015 14:21
Print a matrix taken from Maya node.
proc int widest(float $ary[]) {
int $w = 0;
for ($i = 0; $i < size($ary); $i++) {
string $asString = $ary[$i];
$w = max($w, size($asString));
}
return $w;
}
proc string padFloat(float $value, int $width) {
@ydm
ydm / record-keys.el
Created January 18, 2016 23:29
Emacs: record keys
(defun omg ()
(let ((ch last-command-event)
(tm (current-time)))
(message "ch=%ch, tm=%s" ch tm)))
(add-hook 'post-self-insert-hook #'omg)
@ydm
ydm / DayOfWeek.hs
Last active January 25, 2016 09:31
:: date -> day of week
#!/usr/bin/env runhaskell
import System.Environment
epochYear = 1970
-- Should start with [epochYear jan 1], [1970 jan 1] is Thursday.
weekDays = ["Thursday", "Friday" , "Saturday", "Sunday",
"Monday", "Tuesday", "Wednesday"]
isLeap x = x `rem` 400 == 0 || (x `rem` 100 /= 0 && x `rem` 4 == 0)
@ydm
ydm / lazy.cpp
Last active February 10, 2016 15:01
Lazy evaluation in C++
// #include <algorithm>
// #include <ostream>
#include <iostream>
#include <string>
namespace lazy
{
@ydm
ydm / void_template.cpp
Created February 12, 2016 16:26
Void template
template<typename T>
class A
{
public:
virtual T fn() = 0;
};
class B : public A<int>
{
@ydm
ydm / bary.py
Last active February 26, 2016 09:05
Visualize barycentric coords
#!/usr/bin/env python3
'''
What happens when one of the barycentric coordinates is constant? :)
http://i.imgur.com/gsO6egy.png
'''
import numpy as np
from matplotlib import pyplot as plt
@ydm
ydm / userSetup.mel .c
Created April 4, 2016 13:32
Useful on-start Maya stuff
// Open communication ports
//
commandPort -eo -n ":2222"; // reload.py
commandPort -eo -n ":2223"; // Emacs
// Open the plugin manager window
//
// PluginManager; // Always open plugin manager on start-up
// Show stack traces on errors