Skip to content

Instantly share code, notes, and snippets.

@dinolupo
dinolupo / JsonSample.java
Last active October 31, 2017 11:52
JSON Collectors are useful when working with streams and filtering a JsonArray with a results into another JsonArray. In the example below you are filtering for a female gender and creating a JsonArray with all the selected names.
JsonArray contacts = ...;
JsonArray femaleNames =
contacts.getValuesAs(JsonObject.class).stream()
.filter(x->"F".equals(x.getString("gender")))
.map(x->(x.getString("name"))
.collect(JsonCollectors.toJsonArray());
@dinolupo
dinolupo / TestWebException.java
Last active October 30, 2017 09:33
How to manage Exceptions in Java EE Rest Services .
import javax.ejb.ApplicationException;
import javax.ws.rs.WebApplicationException;
import javax.ws.rs.core.Response;
/**
*
* @author Dino Lupo
*/
@ApplicationException(rollback = true)
public class TestWebException extends WebApplicationException {
@dinolupo
dinolupo / Ubuntu-16.04-Developer-Settings.md
Last active March 19, 2017 18:57
Fresh Install of Ubuntu 16.04 LTS

install missing softwares

sudo apt-get -y install vim git zsh tree ack-grep npm guake tmux

install Ubuntu Firewall GUI

sudo apt-get -y install gufw

openjdk and mongodb

sudo apt-get -y install openjdk-8-jdk mongodb

@dinolupo
dinolupo / maven.sh
Created August 21, 2016 08:09
Maven Javadoc And Sources
# When you’re using Maven in an IDE you often find the need for your IDE to resolve source code and Javadocs for your library dependencies. There’s an easy way to accomplish that goal.
mvn dependency:sources
mvn dependency:resolve -Dclassifier=javadoc
# The first command will attempt to download source code for each of the dependencies in your pom file.
# The second command will attempt to download the Javadocs.
# Maven is at the mercy of the library packagers here. So some of them won’t have source code packaged and many of them won’t have Javadocs.
@dinolupo
dinolupo / Open iTerm2 at Finder Location.app
Created June 30, 2016 12:43
AppleScript that opens a new iTerm2 at a file or directory selected location in Finder
on run {input, parameters}
tell application "Finder"
set dir_path to quoted form of (POSIX path of (folder of the front window as alias))
end tell
CD_to(dir_path)
end run
on CD_to(theDir)
tell application "iTerm"
set _term to create window with default profile
@dinolupo
dinolupo / osx-elcapitan-settings.markdown
Last active June 10, 2016 04:37
OS X El Capitan Clean install

OS X Preferences


most of these require logout/restart to take effect

# Set a shorter Delay until key repeat
defaults write NSGlobalDomain InitialKeyRepeat -int 25

# Set a blazingly fast keyboard repeat rate
@dinolupo
dinolupo / OneDarkXcode.dvtcolortheme
Created May 11, 2016 11:40
Xcode Color and Font settings (Dark and Relaxing) using Adobe Source Code Pro Font
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>DVTConsoleDebuggerInputTextColor</key>
<string>0.65098 0.698039 0.752941 1</string>
<key>DVTConsoleDebuggerInputTextFont</key>
<string>Menlo-Bold - 11.0</string>
<key>DVTConsoleDebuggerOutputTextColor</key>
<string>0.65098 0.698039 0.752941 1</string>
@dinolupo
dinolupo / esp8266.md
Last active January 30, 2016 17:19
ESP8266 AT Commands

ESP8266 AT Commands

AT+CWMODE=1
AT+CWQAP
AT+CWLAP
AT+CWJAP="ssid","password"
AT+CIFSR
@dinolupo
dinolupo / mongo-commands.md
Last active November 13, 2015 14:59
Mongo Commands

Exporting a mongo query result to file "products.json"

mongo --quiet databaseName --eval "var c = db.products.find(); while(c.hasNext()) {printjson(c.next())}" > products.json

OR

create a Javascript file like the following:

vim query.js

@dinolupo
dinolupo / low-power-blink.ino
Last active November 3, 2015 11:56
Low Power Blinking Led with Arduino and AT Tiny 85 processor