Skip to content

Instantly share code, notes, and snippets.

@young
young / uniq_comm.sh
Last active January 17, 2024 20:04
Unique committers to a repo over the past year
#!/bin/bash
# Set the start date one year ago
# gdate for OSX; use date for linux
start_date=$(gdate -d "1 year ago" +'%Y-%m-%d')
echo $start_date
# Get the list of unique committers in the past year; filter out email address name to reduce duplicates
unique_committers=$(git shortlog -se --since="$start_date" | sed -e 's/^\s*[[:digit:]]*\s*//' | sort -u | uniq)
class Buffer {
constructor(promises) {
this.buffer = null;
/**
* Collection of resolved promises
* @type {Set}
*/
this._set = new Set();
// Init
this._init(promises);
@young
young / noRepeat.js
Last active August 14, 2019 20:12
Remove duplicate strings
const testStr = 'Let us go us then you you and I.';
function noRepeat1(str) {
const arr = str.split(' ');
return arr.reduce(function(prev, curr, index) {
if (arr.lastIndexOf(curr) === index) {
prev.push(curr);
}
return prev;
}, []).join(' ')
function debounce(fn, time) {
var timeoutId;
return function() {
if (timeoutId) {
return;
};
fn.apply(this, arguments);
timeoutId = setTimeout(function(){
timeoutId = null;
}, time);
@young
young / flatten.js
Last active August 29, 2015 14:11
Javascript flatten array
var testArr = [1,2,[3,4, [5,6,7], 8], 9, 10];
function flatten(item) {
return item.reduce(function(prev, curr) {
if (!Array.isArray(curr)) {
prev.push(curr);
} else {
prev = prev.concat(flatten(curr));
}
return prev;
@young
young / getFunctionName.js
Created June 6, 2014 03:48
Get the name of a function from a line
function getFunctionName(line) {
var m =line.match(/var (.*)= function/);
if (m.length < 1) {
m = line.match(/function([^\(]+)/);
}
return m[1] || false;
};
# Check if every item in a list is the equals some value
if status[0] == 'COMPLETED' and len(set(status)) == 1:
return True
else:
return False
# use a generator to create an in memory list of TRUE or FALSE
# and then use all() to iterate over the list
if len(LIST) > 0 and all(x == 'foo' for x in LIST):