Skip to content

Instantly share code, notes, and snippets.

View exhesham's full-sized avatar
💭
the grass is greener over here, you're the fog that makes it so clear

Hesham Yassin exhesham

💭
the grass is greener over here, you're the fog that makes it so clear
View GitHub Profile
private final Lock lock = new ReentrantLock(isFair);
// usage:
try{
lock.lock();
// Do some stuff
} finally{
lock.unlock();
}
public class RunnableJob implements Runnable{
@Override
public void run() {
}
}
public void runJobs(){
CompletableFuture<Void> f = CompletableFuture.runAsync(new RunnableJob());
f.thenRun(new RunnableJob());
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";
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 {
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// COMPLETED (9) Within onCreateOptionsMenu, use getMenuInflater().inflate to inflate the menu
getMenuInflater().inflate(R.menu.main, menu);
// COMPLETED (10) Return true to display your menu
return true;
}
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 
/*
* 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");
}
<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" />
- kind: ReplicationController
apiVersion: v1
metadata:
name: bad-frontend
labels:
name: bad-frontend
spec:
replicas: 1
selector:
name: bad-frontend
Function<String, Predicate<Ticket>> ticketFor = event -> ticket -> event.equals(ticket.getName());
List<Ticket> tickets = getAllTickets();
Integer soldTicketsForCoolEvent = tickets.stream()
.filter(ticketFor.apply("CoolEvent")).count();