Skip to content

Instantly share code, notes, and snippets.

Its likely more natural for you to type at the bottom of the file so with normal Go we move the cursor to the bottom before reading from the date command.

# bash_profile.sh
alias did="vim +'normal Go' +'r!date' ~/did.txt"
(function {
window.addEventListener('online', doSomething);
window.addEventListener('offline', doSomething);
})()
// @returns: String { "online", "offline" }
function doSomething() {
returns navigator.onLine;
}
--- /dev/null
+++ b/my_file.txt
@@ -0,0 +1,3 @@
+Dear Abby
+I met a new person today
+It was a good day
@theptrk
theptrk / k-shifted-array.js
Created July 18, 2017 03:49
Algo. K shifted array. Find K
// TODO TEST
// given [3,4,5,6,7,8,9,1,2]
// return 7
const test1 = [3,4,5,6,7,8,9,1,2]
const test2 = [8,9,1,2,3,4,5,6,7]
const findk = list => {
if (list[0] < list[list.length-1]) {
return 0;
}
@theptrk
theptrk / phone-number-mnemonics-iteratively.js
Created June 21, 2017 19:39
given a telephone number, return a list of possible mnemonics using a standard US telephone
const phoneNumberMnemonics = (phoneNumber) => {
const letters = ["0", "1", "abc", "def", "ghi", "jkl", "mno", "pqrs", "tuv", "wxyz"]
const numbers = phoneNumber.split('');
const results = [];
const wipStack = [
{ wip: '', remaining: numbers }
];
while (wipStack.length > 0) {
let [wip, remainingNumbers] = wipStack.pop();
if (remainingNumbers.length > 0) {
@theptrk
theptrk / spiral-traversal.js
Created June 20, 2017 04:45
Spiral Traversal of 2D array in JavaScript
const test1 = [
[1]
];
const test2 = [
[1, 2],
[3, 4]
];
const test3 = [
[1, 2, 3],
[4, 5, 6],
// Part 1
// write an array mapping function that can be passed into reduce
const mapping = (transform) => (acc, val) => acc.concat([transform(val)]);
// write an array filtering function that can be passed into reduce
const filtering = (predicate) => (acc, val) => predicate ? acc.concat([val]): acc;
// Part 2
// abstract out the "reduce" logic
const concat = (acc, val) => acc.concat([val]);
// write reduce without Array.reduce
// @param {Array} list
// @param {Function} fn takes (acc, result)
// @acc {*} acc is the starting point or working accumulator
const reduce (list, fn, acc) => {
let i = 0;
var len = list.length;
while(i < len) {
acc = fn(acc, list[i])
@theptrk
theptrk / circle.html
Created August 10, 2016 01:04
This is a circle in css
<!DOCTYPE html>
<html>
<head>
<title>Circle</title>
<style type="text/css">
.circle-container {
width: 150px;
height: 150px;
line-height: 150px;
text-align: center;
@theptrk
theptrk / KaleActions.js
Created September 8, 2015 06:37
Flux with promises
import alt from '../libs/alt';
class KaleActions {
create(data) {
return new Promise((resolve, reject) => {
var post = $.ajax({
type: 'POST',
data: data,
url: '/kaleapi',
});