Skip to content

Instantly share code, notes, and snippets.

Avatar

Allan Hasegawa AllanHasegawa

View GitHub Profile
View FirebaseIDGenerator.kt
/**
* * New version: 30/May/2017
* * Made it more kotlin-like with same functionality ^^
*
* based on: https://gist.github.com/RomansBermans/6f3836188427fbd3b1efcf7e6418f06d
* Fancy ID generator that creates 20-character string identifiers with the following properties:
*
* 1. They're based on timestamp so that they sort *after* any existing ids.
* 2. They contain 72-bits of random data after the timestamp so that IDs won't collide with other clients' IDs.
* 3. They sort *lexicographically* (so the timestamp is converted to characters that will sort properly).
@AllanHasegawa
AllanHasegawa / serialization.kt
Last active Sep 27, 2019
KotlinX Serialization With Sealed Classes Example
View serialization.kt
import kotlinx.serialization.*
import kotlinx.serialization.internal.ArrayListSerializer
import kotlinx.serialization.internal.StringDescriptor
import kotlinx.serialization.json.Json
import kotlinx.serialization.modules.SerializersModule
@Serializable
sealed class Foo {
@Serializable
@AllanHasegawa
AllanHasegawa / cnpj.kt
Last active Feb 21, 2018
Validador de CNPJ usando Kotlin
View cnpj.kt
data class CNPJ(val value: String)
fun CNPJ.isValid(): Boolean {
val cnpj = value
return validateCNPJLength(cnpj) && validateCNPJRepeatedNumbers(cnpj)
&& validateCNPJVerificationDigit(true, cnpj)
&& validateCNPJVerificationDigit(false, cnpj)
}
View compo_completed.js
// Auxiliary code!!!!!
// Ignore and go to "START FROM HERE" below!!!!
function randomInt(min, max) {
min = Math.ceil(min)
max = Math.floor(max)
return Math.floor(Math.random() * (max - min)) + min
}
// Data
@AllanHasegawa
AllanHasegawa / FontCache.kt
Created Jul 8, 2017
Android Async Font Typeface Loading
View FontCache.kt
object FontCache {
private val FONTS_DIR = "fonts/"
private val CACHE = Hashtable<String, Typeface>()
fun notoSansCJK(context: Context, textView: TextView) {
applyTypefaceAsync(context, textView, "NotoSansCJKjp-Regular.otf")
}
View designer.html
<link rel="import" href="../paper-slider/paper-slider.html">
<polymer-element name="my-element">
<template>
<style>
:host {
position: absolute;
width: 100%;
height: 100%;
View designer.html
<link rel="import" href="../polymer/polymer.html">
<polymer-element name="my-element">
<template>
<style>
:host {
position: absolute;
width: 100%;
height: 100%;
View designer.html
<link rel="import" href="../core-scaffold/core-scaffold.html">
<link rel="import" href="../core-header-panel/core-header-panel.html">
<link rel="import" href="../core-menu/core-menu.html">
<link rel="import" href="../core-item/core-item.html">
<link rel="import" href="../core-icon-button/core-icon-button.html">
<link rel="import" href="../core-toolbar/core-toolbar.html">
<link rel="import" href="../core-menu/core-submenu.html">
<link rel="import" href="../paper-button/paper-button.html">
<link rel="import" href="../core-icons/core-icons.html">
<link rel="import" href="../core-icon/core-icon.html">
@AllanHasegawa
AllanHasegawa / gist:310b526568b7157faad4
Created Oct 7, 2014
Cylinder Line Minimum Distance plot
View gist:310b526568b7157faad4
from mpl_toolkits.mplot3d import axes3d
import matplotlib.pyplot as plt
import numpy as np
import scipy as sp
import scipy.optimize
def cylinderLineFirstInterval(cylinderLength, lineP0, lineP1):
l = cylinderLength
p0 = lineP0
p1 = lineP1
@AllanHasegawa
AllanHasegawa / gist:532b83b6a84350402e64
Last active Aug 29, 2015
OpenVDB - create_levelset_volume
View gist:532b83b6a84350402e64
// V type must provide "V::aabb()" and "V::distance(const glm::vec3&)" methods
template <typename GridType, typename V>
typename GridType::Ptr
create_levelset_volume(const V& kVolume, const float kVoxelSize,
const float kHalfWidth)
{
using ValueType = typename GridType::ValueType;
// GridType::ValueType is required to be a floating-point scalar.
BOOST_STATIC_ASSERT(
boost::is_floating_point<typename GridType::ValueType>::value);
You can’t perform that action at this time.