This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import numpy as np | |
| import math | |
| def get_cosine_sim(a, b): | |
| a = np.array(a) | |
| b = np.array(b) | |
| aq = np.square(np.abs(a)) | |
| bq =np.square(np.abs(b)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import numpy as np | |
| def get_ppmi(term_terms): | |
| term_terms = np.array(term_terms) | |
| total = term_terms.sum() | |
| pxy = term_terms / total | |
| px = pxy.sum(axis=1, keepdims=True) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from collections import Counter | |
| import re | |
| def char_ngrams(word, size=1): | |
| """ | |
| Generates character-level n-grams for a given string with start/end markers. | |
| Args: | |
| word (str): The input string to process. | |
| size (int): The length of the n-gram window. Defaults to 1. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* | |
| * @description Gets the euclidian distance of two vectors | |
| * @param {Array.<number>} v1 - a vector of numbers | |
| * @param {Array.<number>} v2 - a vector of numbers | |
| * @returns {number} A float | |
| */ | |
| function euclidian(v1, v2) { | |
| const squares = v1.map((el, idx) => { | |
| const subtr = el - v2[idx]; | |
| return Math.pow(subtr, 2) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Note: Note cryptographically secure. | |
| function randomString(size = 5) { | |
| const stringArray = [...Math.random().toString()].slice(2, 2 + size); | |
| const intArray = stringArray.map(string => parseInt(string, 10)); | |
| let chars = intArray.reduce((acc, c, idx) => { | |
| const charPos = [65,97]; | |
| let charStart = charPos[c%2]; | |
| const charOffset = Math.ceil(Math.random() * 10)%3; | |
| charStart = (charOffset * 8) + charStart; | |
| return String.fromCharCode(c + charStart) + acc; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <dl> | |
| <dt><code>attributes</code></dt> | |
| <dd>{{dd(attributes)}}</dd> | |
| <dt><code>label_hidden</code></dt> | |
| <dd>{{dd(label_hidden)}}</dd> | |
| <dt><code>title_attributes</code></dt> | |
| <dd>{{dd(title_attributes)}}</dd> | |
| <dt><code>label</code></dt> | |
| <dd>{{dd(label)}}</dd> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const wordSeparatorsRegex = /—\.,;:!?‽¡¿⸘()\\[\\]{}<>«»…‘“”"\s/g; | |
| /* | |
| fuck | s|er|ed|ing, motherfucker | |
| shit + s|ton|ing|ting, bullshit | |
| dick + s|head|hole|ed | |
| ass + hole|hat|face | |
| cock +s | |
| */ | |
| const profanityRegex = /((\b)?(fuck)(\w+)?)|((\b)?shit(\w+)?)|((\b)dick(\w+|\b))|((\b)ass(\w+|\b))|((\b)cocks?\b)|((\b)cunts?\b)|((\b)twats?\b)|(wtf)|(stfu)/gi; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| function getUserIP() { | |
| if( array_key_exists('HTTP_X_FORWARDED_FOR', $_SERVER) && !empty($_SERVER['HTTP_X_FORWARDED_FOR']) ) { | |
| if (strpos($_SERVER['HTTP_X_FORWARDED_FOR'], ',')>0) { | |
| $addr = explode(",",$_SERVER['HTTP_X_FORWARDED_FOR']); | |
| return trim($addr[0]); | |
| } else { | |
| return $_SERVER['HTTP_X_FORWARDED_FOR']; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const profanityRegex = /(((\b|\w+)?(fuck|shit|dick|twat|cock|douche|bitch|piss)(\w+|\b))|((\w+|\b)ass?(\b|hole|face|clown))|((\b)cunt(\w+|\b)))/ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * @description calculates the levenshtein distance between words | |
| * @param {string} str a string | |
| * @param {string} str2 another string | |
| * @returns {object} with properties 'steps' and 'transitions' | |
| */ | |
| function levenshtein(str, str2) { | |
| if (typeof str !== 'string' || typeof str2 !== 'string') return; | |
| let [shorter, longer] = [str, str2].sort((a, b) => a.length - b.length); |
NewerOlder