Skip to content

Instantly share code, notes, and snippets.

@benwells
benwells / reduce-example.js
Created May 12, 2016 13:40
Using Array.reduce to sum a property in an array of objects
var accounts = [
{ name: 'James Brown', msgCount: 123 },
{ name: 'Stevie Wonder', msgCount: 22 },
{ name: 'Sly Stone', msgCount: 16 },
{ name: 'Otis Redding', msgCount: 300 } // Otis has the most messages
];
// get sum of msgCount prop across all objects in array
var msgTotal = accounts.reduce(function(prev, cur) {
return prev + cur.msgCount;
@evantoli
evantoli / GitConfigHttpProxy.md
Last active July 31, 2025 12:13
Configure Git to use a proxy

Configure Git to use a proxy

In Brief

You may need to configure a proxy server if you're having trouble cloning or fetching from a remote repository or getting an error like unable to access '...' Couldn't resolve host '...'.

Consider something like:

@LorisBachert
LorisBachert / TikaExtractor.java
Last active April 15, 2025 06:29
Using Apache TIKA to extract the following formats: DOC, DOCX, PPT, PPTX, XLS, XLSX, PDF, JPG, PNG, TXT Note: Tesseract must be installed in order to get JPG and PNG extraction working.
/**
* Uses Tikas {@link AutoDetectParser} to extract the text of a file.
*
* @param document
* @return The text content of a file
*/
@Override
public String extractTextOfDocument(File file) throws Exception {
InputStream fileStream = new FileInputStream(file);
Parser parser = new AutoDetectParser();
@azadkuh
azadkuh / vim-cheatsheet.md
Last active July 17, 2025 09:22
vim / vimdiff cheatsheet - essential commands

Vim cheat sheet

Starting Vim

vim [file1] [file2] ...

@michaelames
michaelames / gist:f16ee975ddad15cf3527
Created April 28, 2015 15:46
Simplest possible example of Java authentication to LDAP Server (including Active Directory)
import java.util.Hashtable;
import java.io.Console;
import javax.naming.Context;
import javax.naming.directory.DirContext;
import javax.naming.directory.InitialDirContext;
public class TestAuth {
public static void main(String[] args) {
@MariusVolkhart
MariusVolkhart / WhereClause.java
Last active November 13, 2024 07:28
A small utility to help you construct SQL query where clauses
/*
* Copyright 2014-2015 Marius Volkhart
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
@dedunumax
dedunumax / .gitignore Java
Last active July 16, 2025 15:24
A complete .gitignore file for Java.
##############################
## Java
##############################
.mtj.tmp/
*.class
*.jar
*.war
*.ear
*.nar
hs_err_pid*
@ankit-rakha
ankit-rakha / checkSFTP
Created September 8, 2014 06:35
check if SFTP is enabled
check the SSH configuration file (in most cases /etc/ssh/sshd_config) and make sure the following line is present and not commented out:
Subsystem sftp /usr/lib/openssh/sftp-server
@jonlabelle
jonlabelle / string-utils.js
Last active June 27, 2025 14:26
Useful collection of JavaScript string utilities.
// String utils
//
// resources:
// -- mout, https://github.com/mout/mout/tree/master/src/string
/**
* "Safer" String.toLowerCase()
*/
function lowerCase(str) {
return str.toLowerCase();
@eznj
eznj / star_wars.ino
Last active September 26, 2023 18:24
Arduino Star Wars Song
const int c = 261;
const int d = 294;
const int e = 329;
const int f = 349;
const int g = 391;
const int gS = 415;
const int a = 440;
const int aS = 455;
const int b = 466;
const int cH = 523;