Skip to content

Instantly share code, notes, and snippets.

@farnoy
farnoy / moderator.rb
Last active December 25, 2015 08:59
Draft rails adapter for access granted
class Roles::Moderator
applies_for -> user { user.moderator? }
definitions do
can :edit, Comment
can :destroy, Thread, locked: false
can :unlock, Thread, If(:locked_by_him)
end
def locked_by_him
@farnoy
farnoy / gcc -march=generic -Q --help=target
Created August 29, 2013 12:01
gcc optimizations for my cpu arch
The following options are target specific:
-m128bit-long-double [disabled]
-m32 [disabled]
-m3dnow [disabled]
-m3dnowa [disabled]
-m64 [enabled]
-m80387 [enabled]
-m8bit-idiv [disabled]
-m96bit-long-double [enabled]
-mabi= sysv
bool exiter::is_handling(const sf::Event::EventType& ev_type) const {
if (ev_type == sf::Event::Closed)
return true;
if (ev_type == sf::Event::KeyPressed)
return true;
else
return controller::is_handling(ev_type);
}
bool exiter::handle(const sf::Event& event, runner& runner) {
@farnoy
farnoy / gist:6024657
Created July 17, 2013 21:27
c++ Constexprs in std::chrono
kuba@kuba-desk ~ $ cat chrono-constexpr.cc
#include <chrono>
int test() {
std::chrono::hours h{1};
std::chrono::minutes m = ++h;
m--;
return m.count();
}
//////////////////////
// Iteracyjne
long long potega(double a, int n)
{
long long w=a;
for (int i = 1; i < n; i++) w *= a;
return wynik;
}
// Rekurencyjne
long long potega(double a, int n)
✘ ⮀ ~ ⮀ dig wp.pl
; <<>> DiG 9.9.2-P2 <<>> wp.pl
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 44720
;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 1
;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 1024
#include <iostream>
using namespace std;
const int m = 1001;
int main() {
ios_base::sync_with_stdio(0);//tu wklej te linie
int n;
cin >> n;
@farnoy
farnoy / hello.rs
Created March 3, 2013 12:49
rust polymorphism
extern mod std;
enum Drawable {
Rectangle(uint, uint, bool),
Triangle(uint, bool)
}
fn draw_triangle(height: uint, empty: bool) {
let mut n = 1;
info!("Drawing %s triangle", (match empty {true => "empty", false => "full"}));
@farnoy
farnoy / merge.cc
Last active December 14, 2015 10:28
Sorting algorithms, cpp
#include <iostream>
#include "common.hh"
#include <algorithm>
using slice = std::tuple<numbers::iterator, numbers::iterator>;
slice merge(slice x, slice y) {
auto left_it = std::get<0>(x),
left_size = std::get<1>(x),
right_it = std::get<0>(y),
describe Group do
describe 'permissions' do
describe '#permissions= setter' do
let(:opts) { {a: 1} }
def g(params = String.new) Group.new(permissions: params).permissions; end
it('accepts hash') { g(opts).should eq(opts) }
it('accepts JSON') { g(JSON.generate opts).should eq(opts) }
it('creates default JSON object') { g.should eq(Hash.new) }
end
end