Skip to content

Instantly share code, notes, and snippets.

@cshtdd
cshtdd / serialize-tree.rb
Created March 23, 2020 15:40
How to Serialize/Deserialize a binary tree
# Binary tree
# 1. value (int)
# 2. left node (Tree or nil)
# 3. right node (Tree or nil)
class Tree
attr_accessor :value
attr_accessor :left_node
attr_accessor :right_node
@cshtdd
cshtdd / tree.rb
Created February 25, 2020 16:22
Find the kth smallest element in a binary tree
#!/bin/ruby
class Node
attr_accessor :value
attr_accessor :left
attr_accessor :right
def initialize(value)
self.value = value
end
@cshtdd
cshtdd / p.c
Created February 25, 2020 15:32
This is a sample C program. It proves what happens when referencing the memory address of a stack variable declared inside a function
/*
# This is a sample C program
# It proves what happens when referencing the
# memory address of a stack variable declared inside a function
# compile and run the program
gcc -o program1 p.c && ./program1
*/
#!/bin/bash
echo "Start Export Process"
echo "Log into Keybase..."
keybase login
echo "Exporting your PGP keys..."
keybase pgp export -o keybase.public.key
keybase pgp export -s -o keybase.private.key

Keybase proof

I hereby claim:

  • I am cshtdd on github.
  • I am camilin87 (https://keybase.io/camilin87) on keybase.
  • I have a public key whose fingerprint is E96A FDA6 5B38 4269 52EB EFC6 22E2 BE7F 4BBE 3543

To claim this, I am signing this object:

import signal
class InterruptableRegion(object):
def __init__(self, sig=signal.SIGINT):
self.sig = sig
self.interrupted = False
self.released = False
self.original_handler = None
def __enter__(self):
@cshtdd
cshtdd / setup_elastic_search_java.sh
Created January 16, 2019 12:04
Setup all the Java versions Elastic Search needs to compile
#!/bin/bash
# desired java versions
JAVA_VERSION_11=11.0.1-open
JAVA_VERSION_10=10.0.2-open
JAVA_VERSION_9=9.0.4-open
JAVA_VERSION_8=8.0.192-zulu
@cshtdd
cshtdd / jasmine-before-each-call-order
Created August 5, 2014 19:05
explain the order in which beforeEach gets called in Jasmine and the test variables scope
describe("jasmine class variables", function() {
var foo = 0;
beforeEach(function() {
foo += 1;
});
it("can be assigned in the before each", function() {
expect(foo).toEqual(1);
});

Keybase proof

I hereby claim:

  • I am camilin87 on github.
  • I am camilin87 (https://keybase.io/camilin87) on keybase.
  • I have a public key ASA2JSY3LscaDn6Gr37cqH1qa4D_ZRzo0ecfvcDwZAk1YAo

To claim this, I am signing this object:

@cshtdd
cshtdd / scala-unstable-identifiers.scala
Last active August 11, 2016 11:40
scala-unstable-identifiers
//paste the contents of this file on a scala console and inspect the results
abstract class Token
case class TNum(n: Double) extends Token
case class TOpenP() extends Token
case class TCloseP() extends Token
case class TSum() extends Token
case class TDiff() extends Token
case class TMult() extends Token
case class TDiv() extends Token