Skip to content

Instantly share code, notes, and snippets.

View LizardLeliel's full-sized avatar

Evan Larose LizardLeliel

  • Halifax, Canada
View GitHub Profile
@LizardLeliel
LizardLeliel / DynamicLinkedList.cpp
Last active August 29, 2015 14:08
Dynamic Linked List
#include <iostream>
using namespace std;
int main(int argc, char* argv[]) {
// Node struct
struct Node {
int data;
Node *next;
};
@LizardLeliel
LizardLeliel / FunWithMemory.cpp
Last active August 29, 2015 14:08
Me playing arround with linked lists and other stuff
#include <iostream>
using namespace std;
// Note: I was a bit tired wrapping this up, so I could use a bit more code comments
// And I didn't clean up a few things to have "proper coding style", normally mixing
// variables beginning with capitals and what not
// Note2 (Wrotten after it was uploaded): it looks like I was dynamically adding nodes to the
// linked list wrong, they should be added at the head, not the tail.
// Also, I'll work on being consistent on my code style in next ones, I'll just leave things here
@LizardLeliel
LizardLeliel / NegativeIndex.c
Last active August 29, 2015 14:08
Using p[-1], and getting defined behaviour
#include <stdio.h>
#include <stdlib.h>
int main(void) {
int *p = (int*)malloc(sizeof(int)*2);
*p = 4;
++p;
*p = 2;
printf("%d", p[-1]); /* Prints 4 */
return 0;
}
@LizardLeliel
LizardLeliel / SampleRuby.rb
Created November 7, 2014 17:42
I plan to show this small code to a friend soon, to show him ruby
# ==== Basics =====
#This is how you comment in Ruby! Think # is like a //
puts "Hello, World!"
#Equivalent to System.out.println("Hello, World!");
print "Type something in: "
#Equivalent to System.out.print("Type something in: ")\
@LizardLeliel
LizardLeliel / DynamicNodes.cpp
Last active August 29, 2015 14:09
A struct which can be used for linked lists which holds any data
#include <iostream>
#include <cstdlib>
struct dynamicNode {
void* data;
int type;
dynamicNode* next;
};
// I've uploaded this so I may self-reference it later
@LizardLeliel
LizardLeliel / IWasBored.C
Created November 13, 2014 22:04
I was bored :V. Have fun
#include <stdlib.h>
typedef struct Node{void*data;int type;struct Node*next;}dynamicNode;int main()
{dynamicNode*first=(dynamicNode*)malloc(sizeof(dynamicNode));first->next=
(dynamicNode*)malloc(sizeof(dynamicNode));int m=4;float q=4.5;first->data=(void
*)(&m);first->next->data=(void*)(&q);printf("%f\n",(*(int*)first->data+*(float*
)first->next->data));int*a=(int*)malloc(sizeof(int));float*b=(float*)malloc(
sizeof(float));first->next->next=(dynamicNode*)malloc(sizeof(dynamicNode));
first->next->next->next=(dynamicNode*)malloc(sizeof(dynamicNode));first->next->
next->data=(void*)a;first->next->next->next->data=(void*)b;*a=5;*b=22.4;printf(
"%f\n",(*(int*)first->next->next->data+*(float*)first->next->next->next->data))
@LizardLeliel
LizardLeliel / FloatingBinaries
Created November 14, 2014 17:53
It actually prints out the binaries of double numbers
#include <cstdlib>
#include <cstdio>
#include <iostream>
// Last one is for cin.ignore()
using namespace std;
typedef enum binDigPlaces {
b1 = 0x01,
b2 = 0x02,
b3 = 0x04,
@LizardLeliel
LizardLeliel / SortedLinkedListInsertion.c
Created December 6, 2014 17:34
Just a snippit to show someone
void pushSortedAdjNode(adjNode** listHead, int newID, int newDistance) {
adjNode* newNode = malloc(sizeof(adjNode));
newNode->id = newID;
newNode->distance = newDistance;
if (*listHead == NULL || (*listHead)->distance >= newDistance) {
newNode->next = *listHead;
*listHead = newNode;
return;
}
@LizardLeliel
LizardLeliel / RubyRot.rb
Created December 31, 2014 17:34
Ruby class for 2x2 matrices, plus a section that rotates around a grid
# Our class
class Matrix2by2
# Initialize with a 2x2 list
def initialize(x, y)
if not (x.is_a? Array and y.is_a? Array) then
throw(:notArray)
end
if (x.length != 2 and y.length != 2) then
throw(:notEqual)
@LizardLeliel
LizardLeliel / matrices.rb
Last active August 29, 2015 14:12
Amazing. Happy new year!
class Vec < Array
def initialize(ary)
super(@vec = ary)
end
def *(scalar)
Vec.new (
@vec.map { |element|