Skip to content

Instantly share code, notes, and snippets.

View vjdhama's full-sized avatar
🎯
Focusing

Vijay Dhama vjdhama

🎯
Focusing
View GitHub Profile
@vjdhama
vjdhama / OfferAdapter
Created March 1, 2014 14:06
ViewHolder Pattern
package in.mally.volleytest;
import java.util.ArrayList;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;
@vjdhama
vjdhama / shards
Created September 21, 2015 14:25
shards test error
$ make test
/usr/local/bin/crystal run test/*_test.cr
Error in ./test/git_resolver_test.cr:1: while requiring "./test_helper"
require "./test_helper"
^
in ./test/test_helper.cr:1: while requiring "minitest/autorun": can't find file 'minitest/autorun' relative to '/Users/vjdhama/Work/github_codes/shards/test'
require "minitest/autorun"
@vjdhama
vjdhama / foo.cr
Created September 23, 2015 09:22
# Returns a File::Stat object for the named file or raises
# `Errno::ENOENT` (See `File::Stat`)
#
# ```
# echo "foo" > foo
# File.stat("foo").size #=> 4
# File.stat("foo").mtime #=> 2015-09-23 06:24:19 UTC
# ```
def self.lstat(path)
if LibC.lstat(path, out stat) != 0
$ make clean crystal
rm -rf .build
rm -rf ./doc
rm -rf src/llvm/ext/llvm_ext.o
c++ -c -o src/llvm/ext/llvm_ext.o src/llvm/ext/llvm_ext.cc ` --cxxflags`
/bin/bash: --cxxflags: command not found
src/llvm/ext/llvm_ext.cc:1:10: fatal error: 'llvm-c/Core.h' file not found
#include <llvm-c/Core.h>
^
1 error generated.
@vjdhama
vjdhama / stderr.cr
Last active September 27, 2015 15:57
# Code
if Dir.exists?(name) || File.exists?(name)
STDERR.puts "file or directory #{name} already exists"
puts opts
exit 1
end
# Spec
@vjdhama
vjdhama / conditionals.cr
Last active September 29, 2015 10:33
Union Types
if some_condition
name = "foo" #=> String
else
name = false #=> Boolean
end
@vjdhama
vjdhama / overloads_fix.cr
Created September 29, 2015 11:59
Method overloading
def add(x, y)
x + y
end
def add(x : String, y : Int32)
x + y.to_s
end
add(1, 2)
@vjdhama
vjdhama / overloads.cr
Created September 29, 2015 12:00
Method overloading
def add(x, y)
x + y
end
add(1, 2)
add("foo", "bar")
add("foo", 1)
@vjdhama
vjdhama / struct.cr
Last active September 29, 2015 13:24
structs
struct Vehicle
property speed
property color
def initialize(@speed, @color)
end
end
@vjdhama
vjdhama / typed_arguments.cr
Created September 29, 2015 14:20
Typed args
def add(x : Int32, y : Int32)
x + y
end