This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#import <Foundation/Foundation.h> | |
@interface NSArray (Functional) | |
-(NSArray *) dropFirst; | |
-(NSArray *) dropLast; | |
-(NSArray *) map:(id (^)(id element))closure; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[ | |
{ | |
"type": "escape", | |
"width": 30, | |
"align": "left" | |
}, | |
{ | |
"title": "1", | |
"type": "staticButton", | |
"action": "keyPress", |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-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)). |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-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)] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-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)]. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-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). |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |