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
| /* for converting date strings formatted as YYYY-MM-DD into ... other formats. | |
| e.g.: | |
| const dc = new DateConverter('1984-08-09'); | |
| const pretty = dc.format('Started %MMMM %ddd, %yyyy'); | |
| m - lowercase month name | |
| M - variable width month | |
| MM - fixed width month | |
| D - variable width day |
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 | |
| damn +ed, it, goddamn | |
| */ |
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)))/ |
NewerOlder