Skip to content

Instantly share code, notes, and snippets.

View venil7's full-sized avatar
turning coffee into code

Art Deineka venil7

turning coffee into code
View GitHub Profile
{
"caret_extra_width": 1,
"caret_style": "smooth",
"close_windows_when_empty": false,
"color_scheme": "Packages/Oceanic Next Color Scheme/Oceanic Next.tmTheme",
"copy_with_empty_selection": true,
"default_line_ending": "unix",
"detect_slow_plugins": false,
"drag_text": false,
"draw_minimap_border": true,
@venil7
venil7 / gist:8117137
Created December 24, 2013 19:43
up/down
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>list</title>
<style>
.stoppable {
background-color: gray;
}
var throttle2 = function(fn, threshhold, scope) {
var time, last = 0, handle,
args = arguments;
threshhold = threshhold || 250;
return function() {
var that = this;
time = +new Date();
if ((time - last) > threshhold) {
last = time;
// console.timed_log('ran');
@venil7
venil7 / console.timed_log.js
Created December 27, 2013 22:16
console.log, that prints number of milliseconds since last console.log invocation
console.timed_log = function() {
var args = Array.prototype.splice.call(arguments, 0);
var time = +new Date();
var diff = time - (this._time || time);
args.unshift(diff);
console.log.apply(console, args);
this._time = time;
};
@venil7
venil7 / em.js
Last active January 2, 2016 08:09
emphasis function js
var em = function(str, pattern, el) {
if (!(str && pattern)) return "";
pattern = pattern.toString().replace((/[^a-zA-Z1-9 ]/ig), "").split(" ").reduce(function(prev, curr){
if(curr){
prev.push(curr);
}
return prev;
},[]).join("|");
el = el || "em";
process.stdin.setEncoding('utf8');
// becomes readable on every [enter] keystroke
process.stdin.on('readable', function(chunk) {
var chunk = process.stdin.read();
if (chunk !== null) {
console.log(chunk
.split('')
.map(function(c) {
return String.fromCharCode(c.charCodeAt(0)-1);
@venil7
venil7 / required.js
Last active August 29, 2015 13:59
require.js meets ES6 Promises
var required = function(name) {
name = name.toString();
return new Promise(function(resolve, reject) {
require([name], function(module) {
resolve(module);
},
function(err){
reject(err);
});
});
PS1='\[\033[01;32m\]art\[\033[01;34m\] \w\[\033[31m\]$(__git_ps1 "(%s)") \[\033[01;34m\]$\[\033[00m\] '
@venil7
venil7 / insert-sort.js
Created April 27, 2015 16:39
insert sort implementation
var array = [1,7,5,9,0,4,12,56,7,0,45,8,2,3,6,7,8,1,5,0];
Array.prototype.move = function (old_index, new_index) {
if (new_index >= this.length) {
var k = new_index - this.length;
while ((k--) + 1) {
this.push(undefined);
}
}
this.splice(new_index, 0, this.splice(old_index, 1)[0]);
return this; // for testing purposes
@venil7
venil7 / merge_sort.js
Created April 28, 2015 11:33
merge sort
var array = [1, 7, 5, 9, 0, 4, 12, -56, 7, 0, -45, 8, 2, 3, 6, 7, 8, 1, 5, 0,1, 7, 5, 9, 0, 4, 12, -56, 7, 0, -45, 8, 2, 3, 6, 7, 8, 1, 5, 0,1, 7, 5, 9, 0, 4, 12, -56, 7, 0, -45, 8, 2, 3, 6, 7, 8, 1, 5, 0,1, 7, 5, 9, 0, 4, 12, -56, 7, 0, -45, 8, 2, 3, 6, 7, 8, 1, 5, 0,1, 7, 5, 9, 0, 4, 12, -56, 7, 0, -45, 8, 2, 3, 6, 7, 8, 1, 5, 0,1, 7, 5, 9, 0, 4, 12, -56, 7, 0, -45, 8, 2, 3, 6, 7, 8, 1, 5, 0,1, 7, 5, 9, 0, 4, 12, -56, 7, 0, -45, 8, 2, 3, 6, 7, 8, 1, 5, 0];
var merge = function(left, right) {
var ret = [];
var length = left.length>right.length? left.length : right.length;
while(!!left.length || !!right.length) {
var l = left[0];
var r = right[0];
if (l === undefined || l > r) { ret.push(right.shift()); continue;}
if (r === undefined || r >= l) { ret.push(left.shift()); continue;}
}