Instantly share code, notes, and snippets.

Jay Bienvenu jbnv

View GitHub Profile
jbnv / Basic
Last active Jan 12, 2018
Vim Quick Reference
View Basic

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
jbnv / js.cson
Created Sep 11, 2017
Atom Snippets
View js.cson
'body': """
jbnv / csv.php
Created Feb 15, 2017
Convert various list formats to arrays.
View csv.php
$csv = <<<CONTENT
$outbound = array();
foreach(explode("\n",$tsv) AS $line) {
$a = explode(",",$line);
$outbound[$a[0]] = $a[1];
jbnv / shim.php
Created Feb 3, 2017
Debugging shim for PHP.
View shim.php
echo '<p>['.__FILE__.':'.__LINE__.'] GOOD</p>';
try {
// some command here
} catch (Exception $e){
echo '<p>['.__FILE__.':'.__LINE__.'] DIE</p>';
jbnv / coalesce.php
Created Feb 3, 2017
Return the first value that isn't unset, null or empty.
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;
jbnv / domino.js
Created Sep 13, 2016
Function to parse domino strings.
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.
jbnv / circularprimes.js
Created Sep 13, 2016
Function to determine number of circular primes in a range.
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++) {
jbnv / matchesSequence.js
Created Apr 12, 2016
String prototype function that matches a sequence to a string if the string contains all characters in the sequence. (E.g. "love" matches "like a glove")
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);
jbnv / polyfill.js
Created Mar 10, 2016
Polyfill for JavaScript.
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;
jbnv / compare_arrays_of_hashes.rb
Created Mar 1, 2016
A function that goes in Ruby unit tests to check an array of hashes by property. Supply a list of symbols to check.
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"