Skip to content

Instantly share code, notes, and snippets.

View yosriady's full-sized avatar
💡
Optimize for Learning

Yos Riady yosriady

💡
Optimize for Learning
View GitHub Profile
#include "cuPrintf.cu"
#include <stdio.h>
__device__ __host__ int distance(int x1, int y1, int x2, int y2)
{
return (x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2);
}
/* The CPU version of Voronoi Diagram computation */
void cpuVoronoiDiagram(Point2D *points, int *output, int noPoints, int width, int height)
@yosriady
yosriady / magic_box.rb
Created October 26, 2014 15:19
Solution for Palantir Interview Challenge
def read_input
line = STDIN.gets
m, n = line.split(" ").map{|s| s.to_i}
fingerprints = []
m.times do
fingerprints << STDIN.gets.chomp
end
return fingerprints
end
@yosriady
yosriady / watermark.rb
Created October 25, 2014 14:54
Rails Paperclip Multi-page PDF Watermark Processor with MiniMagick
module Paperclip
class Watermark < Processor
WATERMARK_PATH = "#{Rails.root}/public/images/watermark.png"
def initialize(file, options = {}, attachment = nil)
super
@file = file
@watermark_path = options[:watermark_path]
@current_format = File.extname(@file.path)
@basename = File.basename(@file.path, @current_format)
require 'net/https'
require 'json'
uri = URI('https://api.clever.com/v1.1/districts/4fd43cc56d11340000000005/sections?limit=1000000000')
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = true
http.verify_mode = OpenSSL::SSL::VERIFY_PEER
request = Net::HTTP::Get.new(uri.request_uri)
request.add_field 'Authorization', 'Bearer DEMO_TOKEN'
@yosriady
yosriady / max.rb
Created October 1, 2014 08:01
Ruby Max Array unpacking
def max(*values)
values.max
end
(**********************************)
(* Lab 2 : Higher-Order Functions *)
(**********************************)
(* We will discuss the initial part of this Lab as Tutorial
for the Week of 8 Sept *)
(* This lab assignment must be submitted by 16Sept14 6pm *)
(*
Q1: Last via List.fold_Left
@yosriady
yosriady / sheet.rb
Created August 27, 2014 15:03
Rails bitmask_attributes attributes to bitmask conversion
class Sheet < ActiveRecord::Base
bitmask :instruments, :as => [:guitar, :piano, :bass, :mandolin, :banjo, :ukulele, :violin, :flute, :harmonica, :trombone, :trumpet, :clarinet, :saxophone, :others], :null => false
def self.instruments_to_bitmask(instruments)
(instruments & Sheet.values_for_instruments).map { |r| 2**Sheet.values_for_instruments.index(r) }.inject(0, :+)
end
end
@yosriady
yosriady / preview.rb
Created August 27, 2014 15:01
Preview of PDF Paperclip Processor
module Paperclip
# Handles generating preview images of Sheet PDFs
class Preview < Processor
def initialize(file, options = {}, attachment = nil)
super
@file = file
@instance = options[:instance]
@current_format = File.extname(@file.path)
@basename = File.basename(@file.path, @current_format)
@yosriady
yosriady / friendly_id.rb
Created August 25, 2014 06:55
FriendlyId Defaults
# FriendlyId Global Configuration
#
# Use this to set up shared configuration options for your entire application.
# Any of the configuration options shown here can also be applied to single
# models by passing arguments to the `friendly_id` class method or defining
# methods in your model.
#
# To learn more, check out the guide:
#
# http://norman.github.io/friendly_id/file.Guide.html
@yosriady
yosriady / sort.js
Created August 25, 2014 06:54
Rails AJAX Sort
$(document).on("page:change", function() {
$("#sheet_sort_order").change(function () {
data = {
"sort_order": this.value
};
$.get("/sheets", data, undefined, "script");
});
});