Skip to content

Instantly share code, notes, and snippets.

View mrboli's full-sized avatar

Bo Li mrboli

  • Toronto, ON
View GitHub Profile
@mrboli
mrboli / unsub.js
Created March 2, 2016 23:24
Unsubscribe to Meetups on meetup.com
$('input.j-checkbox').each(function(){
if ($(this).attr('checked')) {
$(this).next().trigger('click');
}
});
$('.j-selectbox').val('NO_RECEIVE');
class Business < ActiveRecord::Base
include SubuserExtender
# ...
end
@mrboli
mrboli / async-food-order.js
Last active June 4, 2016 03:00
Callback Example for Erin Kim
// Async
function giveOrderToChef(giveFoodToCustomer){
var food = makeFood();
giveFoodToCustomer(food);
}
function callbackFunction(food) {
goToKitchen(food);
grabFood(food);
bringFoodToCustomer(food)
@mrboli
mrboli / .tmux.conf
Last active October 14, 2016 21:28
dotfiles
# Plugins
run-shell ~/Dev/opensource/tmux-resurrect/resurrect.tmux
run-shell ~/Dev/opensource/tmux-continuum/continuum.tmux
set -g @resurrect-strategy-vim 'session'
set -g @continuum-restore 'on'
setw -g mode-keys vi
bind -n C-k send-keys -R \; clear-history
function chain(fns) {
let c = {};
let toEx = [];
for (let fn in fns) {
this[fn] = fns[fn];
c.[fn] = function () {
toEx.push({ [fn]: arguments });
}
}
@mrboli
mrboli / map-linked-list.js
Created January 10, 2019 01:44
Map fn for Linked Lists
// function Node(data, next = null) {
// this.data = data;
// this.next = next;
// }
function map(head, fn) {
if (!head) return null; // Just return bad nodes
const mappedHead = new Node(fn(head.data));
let lastMappedNode = mappedHead;
@mrboli
mrboli / solution.js
Created April 2, 2020 04:06
Single Number
// hashmap()
// 56 ms, faster than 87.12%
// 37.2 MB, less than 50.00%
function hashmap (nums) {
let existance = {};
for (let i = 0; i < nums.length; i++) {
if (nums[i] in existance === false)
existance[nums[i]] = 1;
else
delete existance[nums[i]];
@mrboli
mrboli / autocomplete.js
Created April 12, 2020 18:38
Autocomplete
/**
* @param {string[]} sentences
* @param {number[]} times
*/
var AutocompleteSystem = function(sentences, times) {
this.trie = { letters: {} };
this.sentences = {};
this.searchInput = '';
sentences.forEach((sentence, sentenceIdx) => {
@mrboli
mrboli / simple_hash_soln.js
Last active April 12, 2020 23:59
Top K Frequent Words Heap Solution [WIP]
var topKFrequent = function(words, k, frequency = {}) {
words.forEach(word => frequency[word] = frequency[word] + 1 || 1);
return Object.keys(frequency).sort((left, right) => {
const freqDiff = frequency[right] - frequency[left];
return freqDiff === 0 ? left.localeCompare(right) : freqDiff;
}).slice(0, k);
};
@mrboli
mrboli / no_optimization.js
Last active April 13, 2020 21:17
All Concat Words
var findAllConcatenatedWordsInADict = function(words) {
words.sort((a, b) => a.length - b.length);
let wordSet = new Set();
words.forEach(word => {
// Use Trie
if (word) wordSet.add(word);
});
// DFS