This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private final Lock lock = new ReentrantLock(isFair); | |
// usage: | |
try{ | |
lock.lock(); | |
// Do some stuff | |
} finally{ | |
lock.unlock(); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class RunnableJob implements Runnable{ | |
@Override | |
public void run() { | |
} | |
} | |
public void runJobs(){ | |
CompletableFuture<Void> f = CompletableFuture.runAsync(new RunnableJob()); | |
f.thenRun(new RunnableJob()); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class FilterLogin implements Filter { | |
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain){ | |
// inject cookie | |
Cookie c = getCookie(httpServletResponse, "WASReqURL"); | |
if(c == null){ | |
// inject the cookie if it is not there | |
c = new Cookie("WASReqURL", ""); | |
httpServletResponse.addCookie(c); | |
} | |
String newUrl = "/my_action_servlet"; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Uri builtUri = Uri.parse(BASE_URL).buildUpon() | |
// add various params | |
.appendQueryParameter(PARAM_QUERY, githubSearchQuery) | |
.appendQueryParameter(PARAM_SORT, sortBy) | |
// build the uri | |
.build(); | |
// Convert the Uri to a URL: | |
URL url = null; | |
try { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class MainActivity extends AppCompatActivity { | |
@Override | |
protected void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
setContentView(R.layout.activity_main); | |
// other code to setup the activity | |
} | |
// other code | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Iterate through the array and append the Strings to the TextView. The reason why we add | |
* the "\n\n\n" after the String is to give visual separation between each String in the | |
* TextView. Later, we'll learn about a better way to display lists of data. | |
*/ | |
for (String toyName : toyNames) { | |
mToysListTextView.append(toyName + "\n\n\n"); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<ScrollView | |
android:layout_width="match_parent" | |
android:layout_height="wrap_content"> | |
<TextView | |
android:id="@+id/tv_weather_data" | |
android:layout_width="wrap_content" | |
android:layout_height="wrap_content" | |
android:padding="16dp" | |
android:textSize="20sp" /> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- kind: ReplicationController | |
apiVersion: v1 | |
metadata: | |
name: bad-frontend | |
labels: | |
name: bad-frontend | |
spec: | |
replicas: 1 | |
selector: | |
name: bad-frontend |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Function<String, Predicate<Ticket>> ticketFor = event -> ticket -> event.equals(ticket.getName()); | |
List<Ticket> tickets = getAllTickets(); | |
Integer soldTicketsForCoolEvent = tickets.stream() | |
.filter(ticketFor.apply("CoolEvent")).count(); | |