Skip to content

Instantly share code, notes, and snippets.

View bzdgn's full-sized avatar
🏠
Working from home

Levent Divilioglu bzdgn

🏠
Working from home
View GitHub Profile
@bzdgn
bzdgn / strtol2.c
Last active April 25, 2016 02:37
strtol() Demo #2
#include <stdio.h>
#include <stdlib.h>
int main()
{
char * numbers = "12 156 101";
for (int i = 0; *numbers != NULL; i++)
printf("%d : %ld\n", i, strtol(numbers, &numbers, 10));
@bzdgn
bzdgn / binary.c
Last active April 22, 2016 01:21
A Simple Program To Print Integer In Binary
#include <stdio.h>
void printBinary(int);
int toInt(int*, char[]);
int handleProgram(char[]);
int main(int argc, char *argv[])
{
return handleProgram(argv[1]);
}
@bzdgn
bzdgn / leap.c
Created April 17, 2016 03:14
Leap Year Demo in C
#include <stdio.h>
typedef enum { FALSE, TRUE } boolean;
boolean isLeapYear(int);
char* getLeapInfo(int);
int main()
{
for(int i = 1980; i <= 2017; i++)
@bzdgn
bzdgn / GameOfLifeDemoV2.java
Created April 2, 2016 05:20
A Simple Conway's Game Of Life Demo in Java Version #2
public class GameOfLifeDemoV2 {
private static final int HEIGHT = 10;
private static final long PERIOD = 120*1;
public static void main(String[] args) throws InterruptedException {
boolean [][] matrix = new boolean[HEIGHT][HEIGHT];
// generateRandom(matrix); // random values matrix
// testGlider(matrix); // test for Glider
testTumbler(matrix); // test for Tumbler
@bzdgn
bzdgn / GameOfLifeDemo.java
Last active April 1, 2016 22:20
A Simple Conway's Game Of Life Demo in Java
public class GameOfLifeDemo {
private static final int HEIGHT = 10;
private static final long PERIOD = 120*1;
public static void main(String[] args) throws InterruptedException {
boolean [][] matrix = new boolean[HEIGHT][HEIGHT];
// generateRandom(matrix); // random values matrix
// testGlider(matrix); // test for Glider
testTumbler(matrix); // test for Tumbler
@bzdgn
bzdgn / InPlaceSwapDemo.java
Last active April 1, 2016 15:21
In-Place Swap Demo
import java.util.Arrays;
public class InPlaceSwapDemo {
public static void main(String[] args) {
int[] numbers = {3, 7};
char[] str = {'b', 'z'};
System.out.println("int In-Place Swap");
@bzdgn
bzdgn / SimpleGOL.java
Created March 9, 2016 06:37
A Very Simple Game Of Life Implementation for Java
public class SimpleGOL {
private static final int HEIGHT = 80;
private static final int CLEAR_SPACE = 2;
public static void main(String[] args) throws InterruptedException {
boolean [][] matrix = new boolean[HEIGHT][HEIGHT];
boolean [][] tempMatrix = new boolean[HEIGHT][HEIGHT];
for(int i = 0; i < matrix.length; i++)
@bzdgn
bzdgn / EqualsOrOperatorDemo,java
Created March 7, 2016 08:07
Equals and == Operator Demonstration
public class EqualsOrOperatorDemo {
public static void main(String[] args) {
String str1 = "Hello";
String[] strArray = new String[] { "animal", "donkey", new String("Hell") + new String("o"), "ox" };
if( str1 == strArray[2] )
System.out.println(" == Operator says : " + str1 + " = " + strArray[2]);
else
System.out.println(" == Operator says : " + str1 + " != " + strArray[2]);
@bzdgn
bzdgn / HashForLong.java
Created March 7, 2016 07:27
Generating 32-bit Integer Hash Code for 64-bit long values with folding
package com.levo.hashing;
public class HashForLong {
public static void main(String[] args) {
long longValueOne = new Long(Integer.MAX_VALUE) + new Long(Integer.MAX_VALUE) + new Long(10);
long longValueTwo = 8;
// Following hashing function is not working, different numbers return same result
System.out.println("Hash[dummyHash] for longValueOne : " + dummyHash(longValueOne));
@bzdgn
bzdgn / callback-with-anonymous-function.html
Last active February 15, 2016 09:59
JavaScript Callback with Anonymous Function Demo
<html>
<body>
<h1>OUTPUT;</h1>
<p id="demo"></p>
<script>
"use strict";
var maxTime = 1000;
var outbox = document.getElementById("demo");