Skip to content

Instantly share code, notes, and snippets.

View railsstudent's full-sized avatar
🏠
Researching third-party library

Connie Leung railsstudent

🏠
Researching third-party library
View GitHub Profile
@railsstudent
railsstudent / localStorageMock.ts
Created October 19, 2018 08:03 — forked from wzr1337/localStorageMock.ts
Mock localStorage for jasmine tests in TypeScript. This is the testing script. Copy the parts between snip and snap to mock your localStorage
/// <reference path="../../library.test.d.ts"/>
import * as angular from "angular"; angular;
import * as mocks from "angular-mocks/ngMock"; mocks;
describe('feat(localStorage Mock): ', function() {
beforeAll(() => {
angular.module('mock-module',[])
});
@railsstudent
railsstudent / connect4.js
Created July 27, 2018 10:32
check if a piece can win a connect 4 game
const COLUMNS = 7;
const ROWS = 6;
const grid = [];
const height = []; // next available row at column j
for (let j = 0; j < COLUMNS; j++) {
height.push(0);
for (let i = 0; i < ROWS; i++) {
@railsstudent
railsstudent / primeNumberGenerator.js
Created May 20, 2018 06:28
Create a generator function to get the first N prime numbers
function* primeNumber(firstN) {
const notPrimes = [];
const primes = [];
let p = 2;
while (p <= firstN) {
primes.push(p);
for (let i = 2; p * i <= firstN; i++) {
if (!notPrimes.includes(p * i)) {
notPrimes.push(p * i);
}

Keybase proof

I hereby claim:

  • I am railsstudent on github.
  • I am connieleung (https://keybase.io/connieleung) on keybase.
  • I have a public key ASA3Ysv7oXXzgowqK-0hdfqiVvp4-W_zr-7CPmxKC4fOyAo

To claim this, I am signing this object:

// Async function returns promise
async function asyncFunc() {
return "123";
}
async function resolveAfter1Second(n) {
return new Promise(resolve => {
setTimeout(() => {
resolve(n);
@railsstudent
railsstudent / Nonesense.api
Created August 27, 2017 05:59
Practice how to create modular code using IIFE pattern
var NonsenseAPI = (function() {
var publicAPI = {
name,
gender,
profession,
languages
};
function name(nickname) {
// Reference: https://godoc.org/github.com/cenkalti/backoff#pkg-examples
// expect the following object to pass to constructor
// {
// retryInterval,
// randomizationFactor,
// multiplier,
// maxInterval,
// maxElapsedTime
// }
function ExponentialBackoff(data) {
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>JS Bin</title>
</head>
<body>
<script src="https://cdnjs.cloudflare.com/ajax/libs/rxjs/4.0.6/rx.all.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/modernizr/2.6.2/modernizr.min.js"></script>
"use strict";
var Observable = Rx.Observable;
var textbox = document.getElementById("textbox");
var textArea = document.getElementById("results");
var keypresses = Observable.fromEvent(textbox, 'keypress');
keypresses.forEach(function (x) {
function getPINs(observed) {
// return [observed].concat(getPINsHelper(observed));
// return getPINsHelper(observed);
let adjacentPins = {
'1': ['1','2','4'],
'2': ['1','2','3','5'],
'3': ['2','3','6'],
'4': ['1','4','5','7'],
'5': ['2','4','5','6','8'],
'6': ['3','5','6','9'],