Instantly share code, notes, and snippets.

View Basic Commands.md

Note: These apply to the Vim-Mode-Plus plugin for Atom and my custom keymaps. This is not a generic reference for Vim.

A "word" is an alphanumeric string. A "WORD" is any series of non-whitespace separated by whitespace.

  • a Append after cursor/at end of line.
  • b Previous word/WORD ("backword").
  • c Change. 🔠 Change to end of line.
  • d Delete. 🔠 Delete to end of line.
  • e End of word.
  • f
View js.cson
'.source.js':
'alert':
'prefix':'//a'
'body': """
//BEGIN TEMP
alert($1);
//END TEMP
"""
'console.log':
'prefix':'//c'
View csv.php
$csv = <<<CONTENT
...
CONTENT;
$outbound = array();
foreach(explode("\n",$tsv) AS $line) {
$a = explode(",",$line);
$outbound[$a[0]] = $a[1];
}
View shim.php
//BEGIN TEMP
echo '<p>['.__FILE__.':'.__LINE__.'] GOOD</p>';
try {
// some command here
} catch (Exception $e){
NsStrings::print_r_block($e);
}
echo '<p>['.__FILE__.':'.__LINE__.'] DIE</p>';
die;
//END TEMP
View coalesce.php
// Return the first value that isn't unset, null or empty.
function coalesce() {
foreach(func_get_args() as $arg) {
if (!empty($arg)) return $arg;
}
return null;
}
View domino.js
/*
Given a string, representing domino tiles chain. Each tile has L-R format, where L and R are numbers from 1..6 range. Tiles are separated by the comma. Some examples of valid S chain are:
1. 1-4,4-2,3-1
2. 6-3
3. 4-3,5-1,2-2,1-3,4-4
Devise a function that, give a domino string, returns the number of tiles in the longest matching group within S. A matching group is a set of tiles that match and that are subsequent in S. Domino tiles match, if the right side of a tile is the same as the left side of the following tile. 2-4,4-1 are matching tiles, but 5-2,1-6 are not.
domino("1-1,3-5,5-2,2-3,2-4") should return 3.
View circularprimes.js
/*
A number is called a circular prime if it is prime and all of its rotations are primes.
For example, the number 197 has two rotations: 971, and 719. Both of them are prime.
Another example: 1193 is a circular prime, since 1931, 9311 and 3119 all are also prime.
*/
function isPrime(n) {
if (n == 1) return false;
for (var i = 2; i <= Math.sqrt(n); i++) {
View matchesSequence.js
if (!String.prototype.matchesSequence) {
String.prototype.matchesSequence = function(sequence) {
if (!sequence) return false;
if (sequence === "") return true;
var pattern = sequence.split("").join(".*");
var exp = new RegExp(pattern);
return exp.test(this);
};
}
View polyfill.js
if (!Array.prototype.includes) {
Array.prototype.includes = function(searchElement /*, fromIndex*/ ) {
'use strict';
var O = Object(this);
var len = parseInt(O.length) || 0;
if (len === 0) {
return false;
}
var n = parseInt(arguments[1]) || 0;
var k;
View compare_arrays_of_hashes.rb
def compare_arrays_of_hashes(expected_array,actual_array,symbols)
expected_array.each_with_index do |expected,index|
actual = actual_array[index]
symbols.each do |symbol|
assert_equal expected[symbol],actual[symbol],"#{symbol} of element #{index} doesn't match"
end
end
end