Skip to content

Instantly share code, notes, and snippets.

View Ceroce's full-sized avatar

Renaud Pradenc Ceroce

View GitHub Profile
@Ceroce
Ceroce / main.purs
Created January 14, 2024 14:42
PureScript Halogen — Draw into a Canvas
module Main where
import Prelude
import Data.Foldable (for_)
import Effect (Effect)
import Effect.Class (class MonadEffect)
import Graphics.Canvas (getCanvasElementById, getContext2D)
import Graphics.Canvas as Canvas
import Halogen as H
@Ceroce
Ceroce / NSArray+Functional.h
Created November 19, 2021 10:07
Category on NSArray to add functional operators
#import <Foundation/Foundation.h>
@interface NSArray (Functional)
-(NSArray *) dropFirst;
-(NSArray *) dropLast;
-(NSArray *) map:(id (^)(id element))closure;
@Ceroce
Ceroce / FrenchProgrammer.json
Created May 1, 2020 10:18
MTMR Preset for a TouchBar with digits, a dot, and square brackets
[
{
"type": "escape",
"width": 30,
"align": "left"
},
{
"title": "1",
"type": "staticButton",
"action": "keyPress",
@Ceroce
Ceroce / palin.erl
Created July 6, 2017 13:46
Determine if a string is a palindrome
-module (palin).
-export ([palindrome/1, cleanString/1]).
% "Madam, I\'m Adam." must return true
palindrome(String) ->
palinClean(cleanString(String)).
palinClean(String) ->
{HeadHalf, TailHalf} = lists:split(length(String) div 2, String),
lists:prefix(HeadHalf, lists:reverse(TailHalf)).
@Ceroce
Ceroce / nub.erl
Created July 6, 2017 10:25
The nub() function removes duplicates from a list
-module (nub).
-export ([nub/1, containsElement/2]).
% Remove duplicates in a list, keeping the order of the last occurences
-spec nub([T]) -> [T].
nub([]) -> [];
nub([X|Xs]) ->
case containsElement(Xs, X) of
true -> nub(Xs);
false -> [X|nub(Xs)]
-module (take).
-export ([take/2]).
% Take the first N elements of a list.
% N may be larger than the length of the list, in which case the whole list is returned.
-spec take(integer(),[T]) -> [T].
take(0, _) -> [];
take(_,[]) -> [];
take(N,[X|Xs]) -> [X|take(N-1, Xs)].
@Ceroce
Ceroce / recursion.erl
Created June 27, 2017 10:09
Erlang: Fibonacci with Tail recursion + determining if an integer is perfect.
-module(recursion).
-export([fib/1, fibtail/1, fibtail/3, isPerfect/1]).
fib(0) ->
0;
fib(1) ->
1;
fib(N) when N > 0 ->
fib(N-1)+fib(N-2).
@Ceroce
Ceroce / CGImageFromCVPixelBuffer.m
Created March 30, 2017 13:49
Create a CGImage from a CVPixelBuffer
CVPixelBufferLockBaseAddress(pixelBuffer, kCVPixelBufferLock_ReadOnly);
void *baseAddr = CVPixelBufferGetBaseAddress(pixelBuffer);
size_t width = CVPixelBufferGetWidth(pixelBuffer);
size_t height = CVPixelBufferGetHeight(pixelBuffer);
CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
CGContextRef cgContext = CGBitmapContextCreate(baseAddr, width, height, 8, CVPixelBufferGetBytesPerRow(pixelBuffer), colorSpace, kCGImageAlphaNoneSkipLast);
CGImageRef cgImage = CGBitmapContextCreateImage(cgContext);
CGContextRelease(cgContext);