Skip to content

Instantly share code, notes, and snippets.

@vbalazs
vbalazs / Prolog-magic.txt
Created May 8, 2013 00:24
Deklaratív programozás nagyzárthelyi, 2005. május 35., Prolog, 4. feladat Bármennyire is utálatos nyelv a prolog, ez azért elég epic. Elmentem ezt emlékeztetőnek, hogy azért lehet(ne) szeretni.
4. Egy számlistában csúcsnak hívunk három szomszédos
elemet, ha az elsõ és a harmadik kisebb a másodiknál.
Írjon olyan Prolog eljárást csucsa néven, amely balról jobbra haladva
felsorolja egy számlistában levõ csúcsokat! A három szomszédos elemet
egy cs/3 funktorú struktúraként adja vissza! Segédeljárást nem
definiálhat.
% csucsa(+L, -Cs): Cs egy cs/3 funktorú struktúra, amely az L számlistában
% levõ csúcsot ír le. L bemenõ, Cs kimenõ paraméter.
@vbalazs
vbalazs / introrx.md
Last active August 29, 2015 14:10 — forked from staltz/introrx.md

The introduction to Reactive Programming you've been missing

(by @andrestaltz)

So you're curious in learning this new thing called (Functional) Reactive Programming (FRP).

Learning it is hard, even harder by the lack of good material. When I started, I tried looking for tutorials. I found only a handful of practical guides, but they just scratched the surface and never tackled the challenge of building the whole architecture around it. Library documentations often don't help when you're trying to understand some function. I mean, honestly, look at this:

Rx.Observable.prototype.flatMapLatest(selector, [thisArg])

Projects each element of an observable sequence into a new sequence of observable sequences by incorporating the element's index and then transforms an observable sequence of observable sequences into an observable sequence producing values only from the most recent observable sequence.

@vbalazs
vbalazs / gist:3dc82da8ea1ea807d510
Created May 31, 2015 16:57
Remove redis keys with pattern
redis-cli KEYS "session:*" | xargs -n 100 redis-cli DEL
@vbalazs
vbalazs / active_record_gem.rb
Created October 7, 2016 08:27
ActiveRecord 4 save generates incorrect INSERT statement after deserialization
begin
require "bundler/inline"
rescue LoadError => e
$stderr.puts "Bundler version 1.10 or later is required. Please update your Bundler"
raise e
end
gemfile(true) do
source "https://rubygems.org"
# Activate the gem you are reporting the issue against.
@vbalazs
vbalazs / s3_temp_image.rb
Created January 29, 2017 15:08
Grape validator to check file existence, size and content type on a given temporary bucket. This is useful when your frontend app only has access to a S3 bucket for temp files (with auto expiry policies for example). It uploads images from javascript and just passes the file id to the Grape API backend where we copy the image to the correct plac…
module Validators
# Provides fast image validation on the temp S3 bucket based on the file's metadata
# It checks for Content Type and file size
class S3TempImage < Grape::Validations::Base
MAX_FILE_SIZE = 10 * 1024 * 1024 # 10 MB
attr_reader :attr_name, :file_name, :file_metadata
def validate_param!(attr_name, params)
@attr_name = attr_name