Skip to content

Instantly share code, notes, and snippets.

@isurum
isurum / 0_reuse_code.js
Created July 2, 2014 19:09
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@isurum
isurum / pattern.java
Created March 20, 2017 15:56
Introduction to Java Programming 8th Edition
package learnjava.testing;
/**
* Created by Isuru on 20/03/2017.
*/
public class Main {
public static void main(String args[]){
System.out.println(" J A V V A");
System.out.println(" J A A V V A A");
System.out.println("J J AAAAA VV AAAAA");
@isurum
isurum / SentinelValueUsingConfirmationDialog.java
Last active March 23, 2017 12:27
A program displays an input dialog to prompt the user to enter an integer (line 11) and adds it to sum (line 15). Line 17 displays a confirmation dialog to let the user decide whether to continue the input. If the user clicks Yes, the loop continues; otherwise the loop exits. Finally, the program displays the result in a message dialog box (line…
package learnjava.testing;
import javax.swing.*;
/**
* Created by Isuru on 20/03/2017.
*/
public class Main {
public static void main(String args[]){
@isurum
isurum / RandomCharacter.java
Created March 23, 2017 16:24
A random integer between (int)'a' and (int)'z' is, (int)((int)'a' + Math.random() * ((int)'z' - (int)'a' + 1). every character has a unique Unicode between 0 and FFFF in hexadecimal (65535 in decimal). To generate a random character is to generate a random integer between 0 and 65535 using the following expression (note that since 0 <= Math.rand…
package learnjava.general;
/**
* Created by Isuru on 23/03/2017.
*/
public class RandomCharacter {
/** Generates random character */
public static char getRandomCharacter(char ch1, char ch2){
return (char) (ch1 + Math.random() * (ch2 - ch1 + 1));
@isurum
isurum / HelloWorld.java
Created April 7, 2017 11:21
It's a convention to start learning and teaching a programming language using Hello World program.
package uk.co.stableweb;
public class HelloWord {
/**
* Launch the application.
*/
public static void main(String[] args) {
System.out.println("Hello World");
}
@isurum
isurum / web.php
Last active June 16, 2017 15:58
Regular Expression Route Constraints And Names in Laravel web.php
/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| contains the "web" middleware group. Now create something great!
|
*/
@isurum
isurum / pysysinfo.py
Created June 16, 2017 09:56
A System Information Gathering Script Using Python
#!/usr/bin/env python
#A System Information Gathering Script
import subprocess
#Command 1
uname = “uname”
uname_arg = “-a”
print "Gathering system information with %s command:\n" % uname
@isurum
isurum / pysysinfo_func.py
Last active June 16, 2017 11:57
Python system info script using functions
#!/usr/bin/env python
#A System Information Gathering Script
import subprocess
#Command 1
def uname_func():
uname = "uname"
uname_arg = "-a"
print "Gathering system information with %s command:\n" % uname
@isurum
isurum / binary_search.py
Created June 22, 2017 09:22
Binary Search implementation using Python.
def search(arr, x, lowest_index, highest_index):
#find the middle index
middle_index = lowest_index + (highest_index - lowest_index) / 2
print "Middle index is ", middle_index
# checks whether the value is in the middle index
if (arr[middle_index] == x):
return middle_index
elif (arr[middle_index] > x):
# checks in <- direction
@isurum
isurum / BinarySearch.java
Created June 22, 2017 11:30
Binary Search Implementation Using Java
package uk.co.stableweb;
public class BinarySearch {
public static void main(String[] args) {
// Create an array
int[] array = {1, 3, 5, 7, 9, 11, 15, 17, 19};
// Initially lowest index is 0
int lowestIndex = 0;