Skip to content

Instantly share code, notes, and snippets.

@sphynx
sphynx / serial.c
Last active December 18, 2018 23:21
Example of functions inside global structures, emulating "Serial" from Arduino language.
#include <stdio.h>
#include <stdlib.h>
typedef void (*func) (const char *);
struct module {
func print;
func println;
};
;; Packages.
(require 'package)
(add-to-list 'package-archives
(cons "melpa-stable" "http://stable.melpa.org/packages/") t)
(package-initialize)
(add-to-list 'load-path "~/elisp") ;; for saving some custom code.
;; Save customizations in a separate file.
(setq custom-file (expand-file-name "custom.el" user-emacs-directory))
;; Packages.
(require 'package)
(add-to-list 'package-archives
(cons "melpa-stable" "http://stable.melpa.org/packages/") t)
(package-initialize)
(add-to-list 'load-path "~/elisp") ;; for saving some custom code.
;; Save customizations in a separate file.
(setq custom-file (expand-file-name "custom.el" user-emacs-directory))
@sphynx
sphynx / gist:813324
Created February 6, 2011 12:01
SSH agent setup in .bashrc
SSH_ENV="$HOME/.ssh/environment"
function start_agent {
echo "Initializing new SSH agent..."
/usr/bin/ssh-agent | sed 's/^echo/#echo/' > "${SSH_ENV}"
echo succeeded
chmod 600 "${SSH_ENV}"
. "${SSH_ENV}" > /dev/null
/usr/bin/ssh-add;
}
(define l_y1 :: int)
(define l_y2 :: int)
(define l_y3 :: int)
(define l_x1 :: int)
(define l_x2 :: int)
(define l_x3 :: int)
(define l_x4 :: int)
(assert (<= l_x1 3))
(assert (>= l_x1 0))
@sphynx
sphynx / gist:878631
Created March 20, 2011 20:11
Haskell solution to Project Euler #14 (now with IOUArray, earlier with State)
module Main where
import Data.List (maximumBy)
import Data.Word (Word64)
import Data.Array.IO (IOUArray, newArray, readArray, writeArray, unsafeFreeze)
import Data.Array.Unboxed (UArray)
import Data.Array.IArray (assocs)
import Control.Monad (forM_)
type Cache = IOUArray Word64 Word64
@sphynx
sphynx / gist:841213
Created February 23, 2011 21:22
Primes test
primes :: [Integer]
primes = sieve [2..]
where
sieve (p:xs) = p : sieve [x | x <- xs, x `mod` p > 0]
main = print $ primes !! 10000
-- compile with `ghc --make primes.hs`, then run run run :)
@sphynx
sphynx / gist:817407
Created February 8, 2011 22:26
Task 3
module Main where
d = [3, 4, 9, 14, 15, 19, 28, 37, 47, 50, 54, 56, 59, 61, 70, 73, 78, 81, 92, 95, 97, 99]
superset [] = [[]]
superset (x:xs) = ss ++ map (x:) ss
where ss = superset xs
check [] = False
check xs = m == sum xs - m where m = maximum xs
@sphynx
sphynx / gist:807906
Created February 2, 2011 16:02
Easing function with tweak
// send first ball from (0, 0) to (200, 0)
animate(firstBall, 0, 200)();
// send second ball from (0, 0) to (100, 0) but with the tempo like it was sent to (200, 0)
animateWithTweak(secondBall, 0, 100, 200)();
function animate(ball, start, intended) {
return function () {
ball.animate({cx: intended}, 2000, ">");
}
@sphynx
sphynx / gist:807908
Created February 2, 2011 16:04
Tweaking Raphael easing function ">"
// send first ball from (0, 0) to (200, 0)
animate(firstBall, 0, 200)();
// send second ball from (0, 0) to (100, 0) but with the tempo like it was sent to (200, 0)
animateWithTweak(secondBall, 0, 100, 200)();
function animate(ball, start, intended) {
return function () {
ball.animate({cx: intended}, 2000, ">");
}