Skip to content

Instantly share code, notes, and snippets.

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

Vasko Zdravevski vaskoz

🏠
Working from home
View GitHub Profile
@vaskoz
vaskoz / embed_struct.go
Created February 28, 2014 16:42
Embedded Structs interview question
package main
import "fmt"
type A struct{}
type B struct {
A
}
func (a A) HiThere() {
@vaskoz
vaskoz / EarlyLateBindings.java
Created February 28, 2014 19:46
Early vs Late Binding in Java
class A {
void print() {
System.out.println(secret());
}
String secret() {
return "A";
}
static void staticPrint() {
System.out.println(staticSecret());
@vaskoz
vaskoz / boot.rb
Created March 1, 2014 22:03
Rails 4.0.3 with TracePoint on Ruby 2.1.1 (MRI)
##### Rails app: config/boot.rb Added by VaskoZ
@stats = {}
@tp = TracePoint.trace(:a_call) do |tp|
@stats[tp.defined_class] ||= {}
@stats[tp.defined_class][tp.method_id] ||= 0
@stats[tp.defined_class][tp.method_id] += 1
end
@tp.enable
##### End VaskoZ changes
# Set up gems listed in the Gemfile.
@vaskoz
vaskoz / gokogiri1.go
Created March 4, 2014 00:09
Simple Gokogiri example file that reads and writes the file.
package main
import (
g "github.com/moovweb/gokogiri"
. "io/ioutil"
_ "fmt"
"os"
)
func main() {
@vaskoz
vaskoz / gokogiri_ex2.go
Created March 6, 2014 15:41
Go Research Skeleton for testing out Gokogiri
package main
import (
g "github.com/moovweb/gokogiri"
"github.com/moovweb/gokogiri/html"
. "io/ioutil"
"fmt"
"os"
"strconv"
)
@vaskoz
vaskoz / optimal_currency.rb
Created March 8, 2014 18:55
The optimal denominations for a currency to reduce the
#denom = popular_usd_denom = [100_00, 50_00, 20_00, 10_00, 5_00, 1_00, 25, 10, 5, 1]
#denom = official_usd_denom = [100_00, 50_00, 20_00, 10_00, 5_00, 2_00, 1_00, 50, 25, 10, 5, 1]
#denom = power2_denom = [64_00, 32_00, 16_00, 8_00, 4_00, 2_00, 1_00, 32, 16, 8, 4, 2, 1]
denom = power3_denom = [27_00, 9_00, 3_00, 1_00, 27, 9, 3, 1]
#denom = power4_denom = [64_00, 16_00, 4_00, 1_00, 64, 16, 4, 1]
total_prices = 100_00
needed = Array.new(total_prices, 0)
denom_count = denom.size
@vaskoz
vaskoz / AscendingSortSpeed.java
Last active August 29, 2015 13:57
Java vs Go built-in sort speed. Testing 1 BILLION integers.
import java.util.*;
public class AscendingSortSpeed {
public static void main(String[] args) {
int[] data = new int[1_000_000_000]; // 1 BILLION INTS
for (int i = 0; i < data.length; i++) {
data[i] = i;
}
// Sort to ascending
long start = System.currentTimeMillis();
@vaskoz
vaskoz / method_types.go
Created March 21, 2014 19:56
Go Method Types
package main
import "fmt"
type Point struct {}
func (p *Point) Scale() {
fmt.Println("method")
}
@vaskoz
vaskoz / for_blocks.go
Created April 12, 2014 17:20
4 different Go For loops, but 2 don't use blocks the same was as the other 2. "for_blocks_fmt.go" is the gofmt version, but it breaks the code by its formatting because it changes the CForLoopNoPrePost example so that it doesn't compile if you add the newline as the original.
package main
// There are 4 FOR examples below, but they differ in how they require
// blocks to start.
import "fmt"
// CANNOT start block on next line
func CForLoop() {
sum := 0
#include <stdio.h>
int main (void)
{
int a = -1;
unsigned int b = 2;
printf("%d\n", 1 > 0); // TRUE == 1
printf("%d\n", 0 > 1); // FALSE == 0
printf("%d\n", a > b); // -1 > 2 apparently TRUE == 1
printf("%d\n", -1 > 2u); // -1 > 2unsigned apparently TRUE == 1
printf("%d\n", -1 > 2); // -1 > 2 FALSE == 0