Skip to content

Instantly share code, notes, and snippets.

Jay Bienvenu jbnv

Block or report user

Report or block jbnv

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@jbnv
jbnv / Basic Commands.md
Last active Jan 12, 2018
Vim Quick Reference
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
@jbnv
jbnv / js.cson
Created Sep 11, 2017
Atom Snippets
View js.cson
'.source.js':
'alert':
'prefix':'//a'
'body': """
//BEGIN TEMP
alert($1);
//END TEMP
"""
'console.log':
'prefix':'//c'
@jbnv
jbnv / csv.php
Created Feb 15, 2017
Convert various list formats to arrays.
View csv.php
$csv = <<<CONTENT
...
CONTENT;
$outbound = array();
foreach(explode("\n",$tsv) AS $line) {
$a = explode(",",$line);
$outbound[$a[0]] = $a[1];
}
@jbnv
jbnv / shim.php
Created Feb 3, 2017
Debugging shim for PHP.
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
@jbnv
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
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
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
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
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
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"
end
end
end
You can’t perform that action at this time.