Skip to content

Instantly share code, notes, and snippets.

View GlenDC's full-sized avatar
🚀

Glen De Cauwsemaecker GlenDC

🚀
View GitHub Profile
package main
import "code.google.com/p/go-tour/pic"
func Pic(dx, dy int) [][]uint8 {
pic := make([][]uint8, dy)
for y := range pic {
pic[y] = make([]uint8, dx)
for x := range pic[y] {
pic[y][x] = uint8(x*y)
@GlenDC
GlenDC / permutations.go
Last active August 29, 2015 14:01
Permations of an array in Go
func Pow(x, n int) int {
return int(math.Pow(float64(x), float64(n)))
}
func Permutations(array []int) [][]int {
size := len(array)
total := Pow(2, size)
permutations := make([][]int, 0, total)
for i := 0; i < total; i++ {
@GlenDC
GlenDC / combinations.go
Last active August 29, 2015 14:01
Combinations of an array in Go
func AllUniqueCombinations_Recursive(combination, array []int, result [][]int) [][]int {
if len(array) > 0 {
for i := range array {
c := make([]int, 0, len(combination))
c = append(c, combination...)
c = append(c, array[i])
a := make([]int, 0, len(array)-1)
a = append(a, array[0:i]...)
a = append(a, array[i+1:]...)
result = AllUniqueCombinations_Recursive(c, a, result)
@GlenDC
GlenDC / grid.elm
Last active August 29, 2015 14:22
Draw Grid
import Color exposing (..)
import Graphics.Collage exposing (..)
import Graphics.Element exposing (..)
import Window
main : Signal Element
main =
Signal.map render Window.dimensions
renderGridLine : Int -> Int -> Int -> Int -> Form
@GlenDC
GlenDC / lazyIf-virtualdom.diff
Last active September 29, 2015 21:44
Proposal for lazyif functionallity in elm-virtualdom
diff --git a/src/Native/VirtualDom.js b/src/Native/VirtualDom.js
index efb9ce7..45ec52e 100644
--- a/src/Native/VirtualDom.js
+++ b/src/Native/VirtualDom.js
@@ -1407,13 +1407,18 @@ Elm.Native.VirtualDom.make = function(elm)
return newNode;
}
+ function predicate(a, b)
+ {
@GlenDC
GlenDC / quine.f90
Last active December 6, 2015 04:43
My first attempt for the Quine Challenge
PROGRAM QUINE
IMPLICIT NONE
INTEGER :: i
CHARACTER(LEN=80), DIMENSION(10) :: Source
Source(1) = "PROGRAM QUINE"
Source(2) = " IMPLICIT NONE"
Source(3) = " INTEGER :: i"
Source(4) = " DO i=1, 3"
Source(5) = " DO i=1, 5"
Source(6) = " END DO"
@GlenDC
GlenDC / quine.py
Created December 6, 2015 04:46
My python version for the Quine Challenge
#!/usr/bin/python
quote = chr(34)
source = [
"#!/usr/bin/python",
"",
"quote = chr(34)",
"source = [",
" ]",
"",
@GlenDC
GlenDC / quine.f90
Last active December 6, 2015 06:13
My second attempt for the Quine Challenge.
PROGRAM QUINE
CHARACTER(LEN=*), PARAMETER :: Quote = Char(39)
CHARACTER(LEN=86), DIMENSION(11) :: Source
INTEGER :: i ; CHARACTER(LEN=2) :: Line
Source( 1) = 'PROGRAM QUINE'
Source( 2) = ' CHARACTER(LEN=*), PARAMETER :: Quote = Char(39)'
Source( 3) = ' CHARACTER(LEN=86), DIMENSION(11) :: Source'
Source( 4) = ' INTEGER :: i ; CHARACTER(LEN=2) :: Line'
Source( 5) = ' DO i=1, 4 ; WRITE(*,*) TRIM(Source(i)) ; END DO'
Source( 6) = ' DO i=1, 11'
@GlenDC
GlenDC / quine.f90
Created December 6, 2015 17:10
A quine that switches between languages
PROGRAM QUINE
IMPLICIT NONE
WRITE(*, '(A)') '#!/usr/bin/python'
WRITE(*, '(A)') ''
WRITE(*, '(A)') 'sq = chr(39) ; dq = chr(34)'
WRITE(*, '(A)') 'ind = lambda str: '' '' + str'
WRITE(*, '(A)') 'sqe = lambda str: sq + str + sq'
WRITE(*, '(A)') 'dqe = lambda str: dq + str + dq'
WRITE(*, '(A)') ''
curl -o quine.py 'https://gist.githubusercontent.com/GlenDC/5ec5528c7fcac5468715/raw/' \
&& python quine.py | python | python