Skip to content

Instantly share code, notes, and snippets.

Allan Hasegawa AllanHasegawa

Block or report user

Report or block AllanHasegawa

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@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 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).
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:db1752da2f982ea0dfb2
Last active Aug 29, 2015
OpenVDB - create_levelset_volume (usage)
View gist:db1752da2f982ea0dfb2
using GridT = openvdb::FloatGrid;
auto grid1 = openvdb::tools::createLevelSetSphere<GridT>(
512.0, openvdb::Vec3f(0, 0, 0), 1, 2);
Sphere s0{glm::vec4(-512,-512,512,1), 16};
LinearSphereSweptVolume volume0(s0, /*translation=*/glm::vec3(1024, 1024, 0));
auto grid2 = create_levelset_volume<GridT>(volume0, 1, 2);
openvdb::tools::csgDifference(*grid1, *grid2);
s0 = Sphere{glm::vec4(-512,512,1024,1), 16};
@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.