Skip to content

Instantly share code, notes, and snippets.

@MJ111
MJ111 / max_substring_solution.cpp
Last active September 20, 2017 18:17
Max Substring
/*
You are given a string S. Find a string T that has the most number of occurrences as a substring in S.
If the solution is not unique, you should find the one with maximum length. If the solution is still not unique, find the smallest lexicographical one.
cabdab
ab
cabcabc
c
@MJ111
MJ111 / checksquare.cpp
Last active October 2, 2017 19:04
csacademy round#50
// can try http://mathworld.wolfram.com/ConvexHull.html, but overkill..
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
int Dist(pair<int, int> a, pair<int, int> b) {
return (a.first - b.first) * (a.first - b.first) +
(a.second - b.second) * (a.second - b.second);
}
@MJ111
MJ111 / manhattan_distance.cpp
Last active October 4, 2017 19:01
Round #51
// https://csacademy.com/contest/round-51/task/manhattan-distances/
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
int main() {
int T, a, b, c, h;
cin >> T;
@MJ111
MJ111 / getQueryParam.js
Last active January 10, 2018 04:35
[get query param] #javascript
/**
* @param {string} name
* @returns {string|null}
* getQueryParam('a') returns '1' on page http://domain.com/page.html?a=1&b=2
**/
function getQueryParam(name) {
const q = window.location.search.match(
new RegExp('[?&]' + name + '=([^&#]*)')
);
return q && q[1];
@MJ111
MJ111 / disableBtnDuringAjax.js
Last active January 11, 2018 03:48
[Disable Button during Ajax] #javascript
/**
* disable clicked button before jQuery ajax request and enable after ajax request finished
* @param {Function} ajaxFn
* ajaxFn should return executed jQuery AJAX function
* @returns {Function}
* returned function should be placed in event listener of Element
*
* Usage:
* $('#deactivate-btn').click(disableBtnDuringAjax(function(e) {
* return $.get('/api/users', function (data) {
@MJ111
MJ111 / get_utc_iso_format.py
Created June 19, 2018 09:00
get_utc_iso_format.py
def get_iso_format():
"""
this returns utc iso8601 string. for example: '2018-06-19T08:51:56+00:00'
"""
import datetime
return datetime.datetime.now(tz=datetime.timezone.utc).replace(microsecond=0).isoformat()
@MJ111
MJ111 / proxy.config
Created January 31, 2019 06:22
[aws eb nginx proxy] #nginx
files:
/etc/nginx/conf.d/proxy.conf:
mode: "000644"
owner: root
group: root
content: |
upstream nodejs {
server 127.0.0.1:5000;
keepalive 256;
}
@MJ111
MJ111 / .bash_profile
Created February 27, 2019 14:38 — forked from natelandau/.bash_profile
Mac OSX Bash Profile
# ---------------------------------------------------------------------------
#
# Description: This file holds all my BASH configurations and aliases
#
# Sections:
# 1. Environment Configuration
# 2. Make Terminal Better (remapping defaults and adding functionality)
# 3. File and Folder Management
# 4. Searching
# 5. Process Management
@MJ111
MJ111 / .bash_profile
Created February 28, 2019 00:11 — forked from stephenll/.bash_profile
.bash_profile file on Mac OS X
# ---------------------------------------------------------------------------
#
# Description: This file holds all my BASH configurations and aliases.
# Much of this was originally copied from:
# http://natelandau.com/my-mac-osx-bash_profile/
#
# Sections:
# 1. Environment Configuration
# 2. Make Terminal Better (remapping defaults and adding functionality)
# 3. File and Folder Management
@MJ111
MJ111 / solution.py
Created March 3, 2019 06:30
[pattern discovery - apriori] feedback'll be appreciated.
import itertools
abs_min_support = 771
freq_items = [None, {}]
# part1
counting = {}
with open('categories.txt', 'r') as f:
while True:
line = f.readline()