Skip to content

Instantly share code, notes, and snippets.

package com.example;
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@ondrej-kvasnovsky
ondrej-kvasnovsky / structjson.js
Created January 24, 2019 12:11
Struct to JSON in JavaScript
/**
* Copyright 2017, Google, Inc.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
@ondrej-kvasnovsky
ondrej-kvasnovsky / app.css
Created July 7, 2015 22:18
Remove shadow from TextArea in JavaFX 8
.text-area {
-fx-background-insets: 0;
-fx-background-color: transparent, white, transparent, white;
-fx-background-radius: 0, 0, 0, 0;
-fx-box-border: none;
-fx-focus-color: -fx-control-inner-background;
-fx-faint-focus-color: -fx-control-inner-background;
-fx-text-box-border: -fx-control-inner-background;
-fx-border-width: -1;
import SwiftUI
let identifiers = NSLocale.availableLocaleIdentifiers
let locale = NSLocale(localeIdentifier: "en_US")
let currencyFormatter = NumberFormatter()
currencyFormatter.numberStyle = .currency
currencyFormatter.usesGroupingSeparator = true
currencyFormatter.maximumFractionDigits = 2
//
// HomeController.swift
// PokeMath
//
// Created by Ondrej Kvasnovsky on 11/19/16.
// Copyright © 2016 Ondrej Kvasnovsky. All rights reserved.
//
import Foundation
import UIKit
@ondrej-kvasnovsky
ondrej-kvasnovsky / oauth.js
Last active October 18, 2021 22:39
How to login with GitHub account and add the GitHub credentials to existing user account
isProdEnv = function () {
if (process.env.ROOT_URL == "http://localhost:3000") {
return false;
} else {
return true;
}
}
Accounts.loginServiceConfiguration.remove({
service: 'google'
@ondrej-kvasnovsky
ondrej-kvasnovsky / client.js
Last active August 3, 2021 17:34
How to send email from Meteor JS framework.
Template.welcomePage.events({
'click #send-email-button': function () {
var email = {
to: 'xyz@failtracker.com',
from: 'abc@failtracker.com',
replyTo: 'abct@failtracker.com',
subject: "test email",
text: "hello lover boy"
};
Meteor.call('sendEmail', this.userId, email);
@ondrej-kvasnovsky
ondrej-kvasnovsky / gist:ea7c76098f7b13eb4fe2469836b0e278
Last active November 4, 2020 17:42
JSON mapping to SQL where conditions
JSON format:
[
"AND",
["GE", ["column", "Price"], 10],
["EQ", ["column", "Product"], "iPhone"],
["NOT",
[
"OR",
["GE", ["column", "Discount"], 1000],
@ondrej-kvasnovsky
ondrej-kvasnovsky / HttpError.ts
Last active October 23, 2020 16:56
NodeJS proxy/gateway using routing-controllers & axios, checking role permissions using Secured annotation
import { HttpError as HE } from 'routing-controllers';
export class HttpError extends HE {
constructor(httpCode: number, message?: string, readonly data?: any) {
super(httpCode, message);
Object.setPrototypeOf(this, HttpError.prototype);
}
toJSON() {
@ondrej-kvasnovsky
ondrej-kvasnovsky / cosineSimilarity.ts
Created September 14, 2020 21:40
Cosine Similarity
function cosineSimilarity(a: number[], b: number[]) {
let dotProduct = 0;
let magnitudeA = 0;
let magnitudeB = 0;
for (let i = 0; i < a.length; i++) {
dotProduct += (a[i] * b[i]);
magnitudeA += (a[i] * a[i]);
magnitudeB += (b[i] * b[i]);
}
magnitudeA = Math.sqrt(magnitudeA);