Skip to content

Instantly share code, notes, and snippets.

View danimal141's full-sized avatar
πŸ’β€β™‚οΈ
Get wild and tough

Hideaki ishii danimal141

πŸ’β€β™‚οΈ
Get wild and tough
  • Tokyo, Japan
View GitHub Profile
@danimal141
danimal141 / exercise-stringer.go
Last active November 25, 2024 13:44
A Tour of Go Exercise: Stringers
package main
import (
"fmt"
"strings"
"strconv"
)
type IPAddr [4]byte
@danimal141
danimal141 / exercise-fibonacci-closure.go
Last active October 10, 2016 08:45
A Tour of Go Exercise: Fibonacci closure
package main
import "fmt"
// fibonacci is a function that returns
// a function that returns an int.
func fibonacci() func() int {
n, a, b := 0, 0, 1
return func() int {
n, a, b = a, b, a + b
@danimal141
danimal141 / exercise-maps.go
Last active October 10, 2016 08:49
A Tour of Go Exercise: Maps
package main
import (
"golang.org/x/tour/wc"
"strings"
)
func WordCount(s string) map[string]int {
m := map[string]int{}
for _, v := range strings.Fields(s) {
@danimal141
danimal141 / exercise-slices.go
Last active October 10, 2016 08:47
A Tour of Go Exercise: Slices
package main
import "golang.org/x/tour/pic"
func Pic(dx, dy int) [][]uint8 {
s := make([][]uint8, dy)
for i := range s {
s[i] = make([]uint8, dx)
}
@danimal141
danimal141 / exercise-loops-and-functions.go
Last active October 10, 2016 09:05
A Tour of Go Exercise: Loops and Functions
package main
import (
"fmt"
"math"
)
func Sqrt(x float64) float64 {
z := 1.0
for {
@danimal141
danimal141 / TypeErasure.swift
Last active March 9, 2017 09:47 — forked from gwengrid/TypeErasure.swift
Example of type erasure with Pokemon
class Thunder { }
class Fire { }
protocol Pokemon {
typealias PokemonType
func attack(move: PokemonType)
}
struct Pikachu: Pokemon {
typealias PokemonType = Thunder
z, d = zd = ['ズン', 'ドコ']
loop.lazy.map { zd.sample }.each_cons(5) do |output|
p output.join('・')
break p('キ・ヨ・シ!') if output == [z, z, z, z, d]
end
public func <(a: NSDate, b: NSDate) -> Bool {
return a.compare(b) == .OrderedAscending
}
public func >(a: NSDate, b: NSDate) -> Bool {
return a.compare(b) == .OrderedDescending
}
public func ==(a: NSDate, b: NSDate) -> Bool {
return a.compare(b) == .OrderedSame
@danimal141
danimal141 / luhn_checksum.rb
Last active August 29, 2015 14:20
Luhn checksum
def check_sum val
sum = val.to_s.each_char.with_index.inject([]) do |memo, (char, i)|
next memo << double_digit_value(char.to_i) if i.odd?
memo << char.to_i
memo
end.inject :+
if (sum % 10).zero?
p "#{sum} is divisible by 10. Valid!"
else
@danimal141
danimal141 / c-pointers.c
Created February 15, 2015 00:14
Pointers in c
#include <stdio.h>
int main() {
int a = 10;
int *pa = &a;
int **ppa = &pa;
printf("%p\n", pa);
printf("%d\n", *pa);
printf("%p\n", ppa);