Skip to content

Instantly share code, notes, and snippets.

View ArielLeslie's full-sized avatar
👻

Ariel ArielLeslie

👻
View GitHub Profile
@ArielLeslie
ArielLeslie / debugging.code-snippets
Created November 19, 2021 19:34
Fancy print console logs to the terminal (VSCode snippets)
{
"Print with labels": {
"scope": "javascript,typescript,javascriptreact,typescriptreact",
"prefix": "console-log-labeled",
"body": [
"// TODO: Don't forget to delete this",
"console.log('\\x1b[35m\\x1b[1m\\x1b[42m%s\\x1b[0m', '################## ${1:LABEL} ##################');",
"console.log($2);",
"console.log('\\x1b[35m\\x1b[1m\\x1b[42m%s\\x1b[0m', '################ END $1 ################');",
],
@ArielLeslie
ArielLeslie / where_do_i_belong.js
Created December 10, 2015 19:21
Return the lowest index at which a value (second argument) should be inserted into an array (first argument) once it has been sorted. For example, where([1,2,3,4], 1.5) should return 1 because it is greater than 1 (index 0), but less than 2 (index 1). Likewise, where([20,3,5], 19) should return 2 because once the array has been sorted it will lo…
function where(arr, num) {
arr.push(num);
arr = arr.sort(function(a, b) { return a - b; });
return arr.indexOf(num);
}
// Tests
console.log(where([10, 20, 30, 40, 50], 35) + " should be 3");
console.log(where([10, 20, 30, 40, 50], 30) + " should be 2");
console.log(where([40, 60], 50) + " should be 1");
/** R T & F A V T W I T T E R B O T **/
/** ======================================= **/
/** Written by Amit Agarwal @labnol on 31/07/2015 **/
/** Tutorial link: http://www.labnol.org/?p=28967 **/
@ArielLeslie
ArielLeslie / grid.html
Created November 24, 2015 23:41
skeleton code for Waypoint: Use the Bootstrap Grid to Put Elements Side By Side
<link href="http://fonts.googleapis.com/css?family=Lobster" rel="stylesheet" type="text/css">
<style>
.red-text {
color: red;
}
h2 {
font-family: Lobster, Monospace;
}
@ArielLeslie
ArielLeslie / convert_html.js
Created November 16, 2015 00:22
Bonfire: Convert HTML Entities
function convert(str) {
var mapping = {
'&' : '&amp;',
':' : '&colon;',
'<' : '&lt;',
'>' : '&gt;',
'"' : '&quot;',
"'" : '&apos;'
};
var words =str.split('');
@ArielLeslie
ArielLeslie / dna_pairing.js
Created October 22, 2015 19:55
Bonfire: DNA Pairing
function pair(str) {
var pairs = [['A', 'T'], ['C', 'G']];
var myPairs = [];
for (i = 0; i < str.length; i++){
for(j = 0; j < pairs.length; j++){
var index = pairs[j].indexOf(str[i]);
if (index >= 0) {
myPairs.push([pairs[j][index], pairs[j][3%(index+2)]]);
}
@ArielLeslie
ArielLeslie / mutations.js
Created October 13, 2015 16:20
Mutatations
function mutation(arr) {
arr[0] = arr[0].toLowerCase();
arr[1] = arr[1].toLowerCase();
for (i = 0; i < arr[1].length; i++){
if(arr[0].indexOf(arr[1].charAt(i)) < 0){
return false;
}
}
return true;
}
@ArielLeslie
ArielLeslie / make_properties_private.js
Created October 6, 2015 17:34
Make Properties Private
//Let's create an object with a two functions. One attached as a property and one not.
var Car = function() {
this.gear = 1;
function addStyle(styleMe){
return 'The Current Gear Is: ' + styleMe;
}
this.getGear = function() {
return addStyle(this.gear);
};
};
@ArielLeslie
ArielLeslie / where_art_thou.js
Created October 6, 2015 17:34
Where Art Thou
function where(collection, source) {
var arr = [];
// What's in a name?
src_keys = Object.keys(source);
arr = collection.filter(function(i){
for(j = 0; j < src_keys.length; j++){
if(!i.hasOwnProperty(src_keys[j]) || i[src_keys[j]] !== source[src_keys[j]]){
return false;
}
}
@ArielLeslie
ArielLeslie / diff_two_arrays.js
Created October 6, 2015 17:33
Diff Two Arrays
function diff(arr1, arr2) {
//just add two two arrays together
var newArr = arr1.concat(arr2);
//then filter it
return newArr.filter(function(val){
// return true if the value is not in one of the arrays
if (arr1.indexOf(val) < 0 || arr2.indexOf(val) < 0){
return true;
}else{
return false;