Skip to content

Instantly share code, notes, and snippets.

View neektza's full-sized avatar

Nikica Jokic neektza

View GitHub Profile

Keybase proof

I hereby claim:

  • I am neektza on github.
  • I am neektza (https://keybase.io/neektza) on keybase.
  • I have a public key whose fingerprint is 7990 35A1 892F DAEE E2F7 485F 3818 D6B1 1712 E2E5

To claim this, I am signing this object:

@neektza
neektza / Event.hs
Created June 11, 2014 15:30
JSON, Aeson and Template Haskell for fun and profit
{-# LANGUAGE OverloadedStrings #-}
module Meetup.Types.Event where
import Data.Text
import Data.Aeson
import Control.Applicative ((<$>), (<*>))
import Control.Monad (mzero)
import Data.ByteString.Lazy
@neektza
neektza / supervision_tree.rb
Last active August 29, 2015 14:02
Ruby concurrency blog post example
require 'bundler/setup'
require 'rubygems'
require 'celluloid'
require 'celluloid/io'
# defining a supervision group via inheritance
class Scraper < Celluloid::SupervisionGroup
supervise Publisher, as: :publisher
supervise Commander, as: :commander
supervise SourceSupervior, as: :source_supervisor,\
@neektza
neektza / basic_methods.rb
Last active August 29, 2015 14:03
Ruby concurrency blog post code snippets
module EventMachine
class Reactor
def run_timers
@timers.each do |t|
if t.first <= @current_loop_time
@timers.delete t
EventMachine::event_callback "", TimerFired, t.last
else
break
@neektza
neektza / query.sql
Created September 26, 2014 10:40
Textacular error
SELECT COUNT("entities".*, COALESCE(ts_rank(to_tsvector('english', "entities"."title"::text), plainto_tsquery('english', 'something'::text)), 0) + COALESCE(ts_rank(to_tsvector('english', "entities"."url"::text), plainto_tsquery('english', 'something'::text)), 0) + COALESCE(ts_rank(to_tsvector('english', "entities"."body"::text), plainto_tsquery('english', 'something'::text)), 0) + COALESCE(ts_rank(to_tsvector('english', "entities"."origin_id"::text), plainto_tsquery('english', 'something'::text)), 0) + COALESCE(ts_rank(to_tsvector('english', "entities"."feed_name"::text), plainto_tsquery('english', 'something'::text)), 0) + COALESCE(ts_rank(to_tsvector('english', "entities"."type_name"::text), plainto_tsquery('english', 'something'::text)), 0) + COALESCE(ts_rank(to_tsvector('english', "entities"."image"::text), plainto_tsquery('english', 'something'::text)), 0) + COALESCE(ts_rank(to_tsvector('english', "entities"."cached_tag_list"::text), plainto_tsquery('english', 'something'::text)), 0) AS "rank323835418192

Keybase proof

I hereby claim:

  • I am neektza on github.
  • I am neektza (https://keybase.io/neektza) on keybase.
  • I have a public key whose fingerprint is 3F15 7202 276C C23B 669F 6C17 1051 AF26 EA1F E905

To claim this, I am signing this object:

@neektza
neektza / hash_table.rs
Created June 7, 2015 20:16
Hash table in Rust, part 1
use std::env;
use std::fs::File;
use std::path::Path;
use std::io::BufReader;
use std::io::prelude::*;
use std::collections::HashMap;
use std::error::Error;
extern crate rand;
use rand::{thread_rng, Rng};
@neektza
neektza / gist:3278569
Created August 6, 2012 21:26
A terminology suggestion

At...

Why are we using anonymous module here? Because we want to stay in the same context, so we can use the prepend variable.

and...

prepend doesn’t exist in the context of the new method, since it’s a local variable. We have to define a method dynamically to use it.

.. maybe better to mention that by defining the module and the method in a block, we stay in the same lexical [closure](http://en.wikipedia.org/wiki/Closure_(computer_science\)), and in that way we can access the local variables. What I'm trying to say is that we don't need to define these things anonymously or dynamically; we just need to define them in a the same lexical closure, and we achieve that by using blocks.

@neektza
neektza / book_example.js
Last active December 18, 2015 16:58
"Functional JavaScript" erratum
// Section: "Prototype-based OO programming", 2nd example
var bFunc = function() { return this }
var b = { name: "b", fun: bFunc }
b.fun()
// => Object {name: "b", fun: function}
@neektza
neektza / service_object.rb
Last active December 19, 2015 00:58
Code snippets for blog post "Objects and Ruby"
class SomeServiceObject
def initialize(foo)
@foo = foo
end
def a_method
manipulate(foo)
end