This file contains 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
/** | |
* These methods only work for an array of numbers | |
*/ | |
function findMinimum(array) { | |
let length = array.length; | |
let min = Infinity; | |
while(length--) { | |
if(array[length] < min) { |
This file contains 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
module CounterIncrementor | |
def next(counter_name) | |
counter = self.find_by(name: counter_name) | |
counter.increment | |
end | |
end | |
class Counter | |
include Mongoid::Document | |
include Mongoid::Timestamps |
This file contains 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 { Dispatch, SetStateAction } from 'react'; | |
/** | |
* This method needs to provide the type of the initialState like | |
* `useObjectState<initialStateInterface>(initialState)` | |
* @param {*} initialState The initial state the user wants to set | |
* @returns Array containing `state` object, `setState` method and `updateState` method | |
*/ | |
function useObjectState<S>(initialState: S): [ | |
S, |
This file contains 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 { useState, useEffect } from 'react'; | |
function getNetworkConnection() { | |
return ( | |
window.navigator.connection | |
); | |
} | |
function getNetworkConnectionInfo() { | |
const connection = getNetworkConnection(); |
This file contains 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
_.mixin({ | |
isHash: function(object) { | |
return _.isObject(object) && !_.isArray(object); | |
}, | |
capitalize: function(string) { | |
return string.charAt(0).toUpperCase() + string.substring(1).toLowerCase(); | |
}, | |
This file contains 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
// load angular | |
fetch('https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.5.8/angular.min.js') | |
.then(response => response.text()) | |
.then(text => eval(text)) | |
// load $ | |
fetch('http://code.jquery.com/jquery-2.1.0.js') | |
.then(response => response.text()) | |
.then(text => eval(text)) |
This file contains 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
var requests = []; | |
var responses = []; | |
var urls = []; // sample urls | |
$.each(urls, function(url) { | |
requests.push( $.get(url, getQueryParams(), function(resp){ responses.push(resp) }) ); | |
}); | |
// here this is the object to which the arguments is to be passed |
This file contains 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
/** | |
* Paste this in the console of a lesson page | |
* | |
* @return [Array] List of urls for a course | |
*/ | |
$.map($('.up-next-list-item'), function(el) { return $(el).attr('href') }); | |
/** | |
* Paste this on the courses page | |
* Tip: convert the list to String by append .join('\n') |
This file contains 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
#!/usr/bin/env ruby | |
# Author : Emad Elsaid (https://github.com/blazeeboy) | |
# | |
# this script is a small practice in implementing | |
# simple sorting algorithms in ruby, i converted | |
# the sorting algorithms from wikipedia pages | |
class Array | |
# Insertion sort is a simple sorting algorithm that builds | |
# the final sorted array (or list) one item at a time. |
This file contains 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
# Question: | |
# Write a RoR program to find the contiguous subarray within a onedimensional | |
# array of numbers (containing at least one positive number) which has the largest sum. | |
# For example, for the sequence of values −2, 1, −3, 4, −1, 2, 1, −5, 4; the contiguous | |
# subarray with the largest sum is 4, −1, 2, 1, with sum 6. | |
# The program should run as follows <bold is user entry>: | |
# Enter the array : | |
# -2 1 -3 4 -1 2 1 -5 4 | |
# => [-2, 1, -3, 4, -1, 2, 1, -5, 4] | |
# Largest SubArray |