Skip to content

Instantly share code, notes, and snippets.

View karellism's full-sized avatar
:electron:
Educating myself

Karel Vanhelden karellism

:electron:
Educating myself
  • Karellism
  • karelvanhelden@gmail.com
View GitHub Profile
@karellism
karellism / AppTerminate.java
Last active June 2, 2019 22:23
How to terminate a Java app
// how to terminate a Java application
import java.io.File;
public class AppTerminate {
public static void main(String[] args) {
File file = new File("config.xml");
int errCode = 0;
if (!file.exists()) {
@karellism
karellism / clearcache.sh
Last active June 2, 2019 22:23
Clears PageCache and Swap in Linux
#!/bin/bash
# echo 1 = clear pagecache, echo 2 clears dentries and inodes, echo 3 clear Pagecache, dentries and inodes
su -c "echo 3 >'/proc/sys/vm/drop_caches' && swapoff -a && swapon -a && printf '\n%s\n' 'Ram-cache and Swap Cleared'" root
@karellism
karellism / inoutstring.c
Created March 3, 2019 23:28
An example C code to read a string from STDIN and printing it out to STDOUT.
include <stdio.h>
int main()
{
char a[100]; //assuming that string size will not exceed 100
scanf("%s",a); //read a string in array a
printf("%s",a); //print out array a
return 0;
}
@karellism
karellism / inout.c
Created March 3, 2019 23:27
An example C code to read an integer from STDIN and printing it out to STDOUT.
#include <stdio.h>
int main()
{
int n;
scanf("%d",&n); //read input integer from STDIN
printf("%d",n); //print output integer to STDOUT
return 0;
}
@karellism
karellism / linkedlistexample.py
Created February 28, 2019 09:08
Linked list example in Python
# Node class
class Node:
# Function to initialize the node object
def __init__(self, v):
self.val = v # Assign value
self.next = None # Initialize next as null
# Linked List class
class ListNode:
# Function to initialize the Linked List
@karellism
karellism / ListNode.java
Created February 28, 2019 09:07
Linked list example in Java
// Linked list class
class ListNode
{
// head of list
Node head;
// Node class
class Node
{
int val;
@karellism
karellism / linkedlistexample.cpp
Created February 28, 2019 09:05
Linked list example in C/C++
// A linked list node
struct ListNode
{
int val;
struct ListNode *next;
};
@karellism
karellism / AddTwoArrays.cpp
Created February 17, 2019 07:36
Adding the Nth value of the first and second array and output their sum untill the limit is reached.
#include <iostream>
using namespace std;
main()
{
int first[20], second[20], c, n;
cout << "Enter the number of elements in the array ";
cin >> n;
@karellism
karellism / InputScanner.java
Created February 15, 2019 08:40
How to get the user input using Scanner. Here the input is an integer that will be stored in int variable i.
Scanner sc = new Scanner(System.in);
int i = sc.nextInt();
@karellism
karellism / ArraysDeclaration.java
Last active February 28, 2019 12:33
2 ways how you can declare an Array in Java.
int intArray[]; //Declaring Array
intArray = new int[20]; //Allocating Memory To Array
int[] intArray = new int[20]; //Combining Both Statements In One Line
int[] intArray = new int[]{ 1,2,3,4,5,6,7,8,9,10 }; //Declaring A Literal Array