Skip to content

Instantly share code, notes, and snippets.

View ice1000's full-sized avatar
♾️
Generalizing something

Tesla Zhang‮ ice1000

♾️
Generalizing something
View GitHub Profile
@ice1000
ice1000 / LanguageExtension.kt
Created August 20, 2016 00:33
Some interesting language extension in kotlin
package org.frice.game.utils.kotlin
/**
* Kotlin language extension
* for Kotlin only
*
*
* Created by ice1000 on 2016/8/17.
* @author ice1000
* @since v0.3.2
// 不得不说,虽然是个水题,但是还是应该保证内存安全,按照@Yoto Chang的说法。于是我就写了一个内存安全的。
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
double **a;
int *x, *y;
int squared (int x) {
@ice1000
ice1000 / C++JniGeneration.kt
Created December 20, 2016 07:33
Using Kotlin to generate JNI C++ codes for my own use
@file:JvmMultifileClass
@file:JvmName("CodeGen")
package org.algo4j.gen
import org.algo4j.test.print
/**
* Created by ice1000 on 2016/12/6.
*
@ice1000
ice1000 / sb.go
Created January 1, 2017 16:46
Java-like StringBuffer for Golang
package sb
import (
"fmt"
"strings"
)
const maxLength = 150
/// a java style string buffer
@ice1000
ice1000 / coping-alpha-of-intellij-icon.kt
Created March 29, 2017 16:51
it makes an icon's alpha value the same as intellij's one's. (I used it to make intellij plugin icon)
import java.io.File
import javax.imageio.ImageIO
/**
* Created by ice1000 on 2017/3/28.
*
* @author ice1000
*/
@ice1000
ice1000 / displaying-fib-matrix-output-as-function.kt
Created March 29, 2017 16:52
This program displays the output of fib-matrix mentioned in my blog
import java.awt.BorderLayout
import java.awt.Color
import java.awt.Graphics
import java.io.File
import javax.swing.JFrame
import javax.swing.JPanel
import javax.swing.WindowConstants
/**
* Created by ice1000 on 2017/3/18.
@ice1000
ice1000 / point-free.kt
Last active April 27, 2017 15:48
A Point-Free function implementation in Kotlin
package main
/**
* Created by ice1000 on 2017/4/27.
*
* @author ice1000
*/
fun <A, B, C : Any> zipWith(op: (A, B) -> C) = { x: Sequence<A> ->
{ y: Sequence<B> ->
@ice1000
ice1000 / kotlin-lambda-rec.kt
Created May 2, 2017 16:14
Kotlin can also write recursive lambda
package main
/**
* Created by ice1000 on 2017/5/2.
*
* @author ice1000
*/
fun main(args: Array<String>) {
fun lambda(it: Int): Int =
@ice1000
ice1000 / FunctionComposition.kt
Created August 24, 2017 14:50
function composition
operator fun <A, B, C> ((B) -> A).plus(p: (C) -> B) = { it: C -> this(p(it)) }
fun main(args: Array<String>) {
val a: (Int) -> String = { it.toString() }
val b: (String) -> ByteArray = { it.toByteArray() }
println((b + a)(233))
val c: (ByteArray) -> List<Int> = { it.map { it.toInt() } }
println((c + b + a)(666)) // Haskell: c . b . a $ 666
}
struct Config { blabla };
typedef int ConfigType;
enum ConfigType_ { Type1, Type2, Type3, TypeCOUNT; };
auto SetConfig(ConfigType type, Config config) -> void {
switch (type) {
case Type1: blablba; break;
case Type2: blablba; break;
case Type3: blablba; break;
default: error(); break;