Skip to content

Instantly share code, notes, and snippets.

View tborisova's full-sized avatar

Tsvetelina Borisova tborisova

View GitHub Profile
@katopz
katopz / gql_search_stargazers.gql
Created November 26, 2016 04:54
GraphQL Github Example : Search for top ten stargazers
// Try at : https://graphql-explorer.githubapp.com/
{
search(query: "language:JavaScript stars:>10000", type: REPOSITORY, first: 10) {
repositoryCount
edges {
node {
... on Repository {
name
descriptionHTML
stargazers {
@ndyakov
ndyakov / main.go
Last active August 29, 2015 14:09
Sleeping Barber Problem
package main
import (
"fmt"
"math/rand"
"time"
)
type Barber struct {
Customer chan *Customer
# This custom matcher can be used to test state machine
#
# Examples
#
# transition = OpenStruct.new(:name => :operation1, :state_field => :status, :from => :state1, :to => :state2)
# it { should have_transition(transition) }
#
# transition = {:name => :operation2, :state_field => :status, :from => :state2, :to => :state3}
# it { should have_transition(transition) }
RSpec::Matchers.define :have_transition do |transition|
@seyhunak
seyhunak / devise_helper.rb
Created September 16, 2013 10:50
Devise Error Messages Twitter Bootstrap style
# /app/helpers/devise_helper.rb
module DeviseHelper
def devise_error_messages!
return '' if resource.errors.empty?
messages = resource.errors.full_messages.map { |msg| content_tag(:li, msg) }.join
sentence = I18n.t('errors.messages.not_saved',
count: resource.errors.count,
resource: resource.class.model_name.human.downcase)
# app / controllers / application_controller.rb
class ApplicationController < ActionController::Base
# Prevent CSRF attacks by raising an exception.
# For APIs, you may want to use :null_session instead.
protect_from_forgery with: :exception
before_filter :configure_permitted_parameters, if: :devise_controller?
protected
def configure_permitted_parameters
@hrdwdmrbl
hrdwdmrbl / ability.rb
Created June 5, 2013 23:06
CanCan -- HowTo cache the ability.rb file
class Ability
include CanCan::Ability
def marshal_dump
#blocks cannot be cached
@rules.reject{|rule| rule.instance_variable_get :@block }.map{|rule| Marshal.dump(rule) }
end
def marshal_load array
#blocks cannot be cached, so blocks must be re-defined
can :read, Comment do |comment|
@praserocking
praserocking / introsort.cpp
Created March 31, 2013 13:23
Introsort implementation in C++
#include <math.h>
#include <algorithm>
#include <iostream>
using namespace std;
void introsort_r(int a[], int first, int last, int depth);
void _introsort(int a[], int n);
int _partition(int a[], int first, int last);
void _insertion(int a[], int n);
void _swap(int *a, int *b);
void _doheap(int a[], int begin, int end);
@ryansobol
ryansobol / gist:5252653
Last active November 22, 2023 11:53
15 Questions to Ask During a Ruby Interview

Originally published in June 2008

When hiring Ruby on Rails programmers, knowing the right questions to ask during an interview was a real challenge for me at first. In 30 minutes or less, it's difficult to get a solid read on a candidate's skill set without looking at code they've previously written. And in the corporate/enterprise world, I often don't have access to their previous work.

To ensure we hired competent ruby developers at my last job, I created a list of 15 ruby questions -- a ruby measuring stick if you will -- to select the cream of the crop that walked through our doors.

What to expect

Candidates will typically give you a range of responses based on their experience and personality. So it's up to you to decide the correctness of their answer.

@henrya2
henrya2 / MergeSortAndCount.cpp
Created January 31, 2013 01:31
A simple merge sort algorithm with Counting Inversions implementation in C++
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
template <typename T>
long long mergeSortAndCountInversions(T* arr, int size)
{
int m;
if (size <= 1)
@rgreenjr
rgreenjr / postgres_queries_and_commands.sql
Last active May 22, 2024 05:53
Useful PostgreSQL Queries and Commands
-- show running queries (pre 9.2)
SELECT procpid, age(clock_timestamp(), query_start), usename, current_query
FROM pg_stat_activity
WHERE current_query != '<IDLE>' AND current_query NOT ILIKE '%pg_stat_activity%'
ORDER BY query_start desc;
-- show running queries (9.2)
SELECT pid, age(clock_timestamp(), query_start), usename, query
FROM pg_stat_activity
WHERE query != '<IDLE>' AND query NOT ILIKE '%pg_stat_activity%'