Skip to content

Instantly share code, notes, and snippets.

@gchumillas
gchumillas / perpendicular_intersection.ts
Created March 13, 2017 23:31
Intersection between the line AB and and the perpendicular line which contains the point C.
interface Point {
readonly x: number;
readonly y: number;
}
/**
* This function returns the intersection between the line AB
* and the perpendicular line that contains the point C.
*/
function intersection(a: Point, b: Point, c: Point): Point {
@gchumillas
gchumillas / myproject.localhost.conf
Last active May 6, 2018 14:20
Apache2, Virtual Host
## File:
# /etc/apache2/sites-available/myproject.localhost.conf
## Enables a virtual host
# a2ensite myproject.localhost.conf
## Disables a virtual host
# a2dissite myproject.localhost.conf
## reloads Apache2
@gchumillas
gchumillas / .sass-lint.yml
Created May 27, 2018 18:53
SASS Lint rules
options:
formatter: stylish
files:
include: '**/*.s+(a|c)ss'
rules:
# Extends
extends-before-mixins: 1
extends-before-declarations: 1
placeholder-in-extend: 1
@gchumillas
gchumillas / tslint.json
Created May 27, 2018 18:54
TypeScript Lint rules
{
"rulesDirectory": [
"node_modules/codelyzer"
],
"rules": {
"arrow-return-shorthand": true,
"callable-types": true,
"class-name": true,
"comment-format": [
true,
@gchumillas
gchumillas / .htaccess
Last active May 28, 2018 19:14
Cross-Origin Resource Sharing (CORS)
Options -Indexes
<IfModule mod_headers.c>
Header set Access-Control-Allow-Origin http://DOMAIN-NAME.com:PORT
Header set Access-Control-Allow-Credentials true
Header add Access-Control-Allow-Methods: "GET,POST,OPTIONS,DELETE,PUT"
Header add Access-Control-Allow-Headers: "Content-Type"
Header add Access-Control-Allow-Headers: "Authorization"
</IfModule>
@gchumillas
gchumillas / ubuntu-mysql-fix
Created August 5, 2018 19:18
MySQL Access denied for user 'root'@'localhost'
```bash
# open the mysql terminal
sudo mysql -u root
```
```text
use mysql;
SELECT User, Host, plugin, authentication_string FROM user;
UPDATE user SET plugin='mysql_native_password', authentication_string=PASSWORD('123456') WHERE User='root';
FLUSH PRIVILEGES;
@gchumillas
gchumillas / AppText.tsx
Last active November 14, 2023 20:12
React Native: how to extend Text component (the "hook" and the "class" way).
import React from 'react'
import { Text, TextProps } from 'react-native'
// The "hook" way.
// The `React.PropsWithChildren` type adds the `children` property to the `TextProps` type.
const AppText1 = ({ children, style, ...rest }: React.PropsWithChildren<TextProps>) => (
<Text style={[{ fontFamily: 'monospace' }, style]} {...rest}>
{children}
</Text>
)
@gchumillas
gchumillas / MainActivity.kt
Created April 10, 2020 10:10
ScaleGestureDetector example (Android, kotlin)
package com.example.myapplication
import android.annotation.SuppressLint
import android.os.Bundle
import android.view.ScaleGestureDetector
import androidx.appcompat.app.AppCompatActivity
import com.example.myapplication.databinding.ActivityMainBinding
@SuppressLint("ClickableViewAccessibility")
class MainActivity : AppCompatActivity() {
@gchumillas
gchumillas / 1_MainActivity.kt
Last active November 11, 2020 16:12
Rotate, Scale and Move in Android (Kotlin)
package com.example.myapplication
import android.annotation.SuppressLint
import android.app.Activity
import android.graphics.Matrix
import android.graphics.PointF
import android.os.Bundle
import android.view.ScaleGestureDetector
import androidx.core.view.doOnLayout
import com.almeros.android.multitouch.MoveGestureDetector
import React from 'react'
import _ from 'lodash'
export type Validator = (val: any) => string | true
const useValidator = ({
defaultValidator = () => true,
validators
}: {
defaultValidator?: Validator