Skip to content

Instantly share code, notes, and snippets.

View zosiu's full-sized avatar

Zsófia Balogh zosiu

  • 14:04 (UTC +02:00)
View GitHub Profile
@zosiu
zosiu / xdg-open
Created December 5, 2013 21:06
Patched /usr/bin/xdg-open script for Lubuntu to open magnet and sublime links.
#!/bin/sh
#---------------------------------------------
# xdg-open
#
# Utility script to open a URL in the registered default application.
#
# Refer to the usage() function below for usage.
#
# Copyright 2009-2010, Fathi Boudra <fabo@freedesktop.org>
# Copyright 2009-2010, Rex Dieter <rdieter@fedoraproject.org>
@zosiu
zosiu / 01_how_to_setup_google_auth_with_devise.md
Last active August 29, 2015 14:08
Rails 4 & devise & google oauth2
  • register a new project here
  • set the followings under APIs & auth:
    • Consent screen: fill out the requires fields
    • APIs: Contacts API & Google+ API
    • Creditentials: create a new OAuth client ID
      • AUTHORIZED JAVASCRIPT ORIGINS: HOST (your app host) (protocol prefixed!)
      • AUTHORIZED REDIRECT URI: HOST/auth/google/callback (protocol prefixed!)
  • sign in url is user_omniauth_authorize_path(:google)
@zosiu
zosiu / human.rb
Created November 2, 2014 05:48
age calculation in ruby
require 'time'
class Human
attr_reader :birth_date
def initialize(birth_date)
@birth_date = birth_date
end
@zosiu
zosiu / verification.rb
Last active August 29, 2015 14:13
Apple In-App Purchase receipt verification
require 'venice'
data = %{ewoJInNpZ25hdHVyZSIgPSAiQXBNVUJDODZBbHpOaWtWNVl0clpBTWlKUWJLOEVkZVhrNjNrV0JBWHpsQzhkWEd1anE0N1puSVlLb0ZFMW9OL0ZTOGNYbEZmcDlZWHQ5aU1CZEwyNTBsUlJtaU5HYnloaXRyeVlWQVFvcmkzMlc5YVIwVDhML2FZVkJkZlcrT3kvUXlQWkVtb05LeGhudDJXTlNVRG9VaFo4Wis0cFA3MHBlNWtVUWxiZElWaEFBQURWekNDQTFNd2dnSTdvQU1DQVFJQ0NHVVVrVTNaV0FTMU1BMEdDU3FHU0liM0RRRUJCUVVBTUg4eEN6QUpCZ05WQkFZVEFsVlRNUk13RVFZRFZRUUtEQXBCY0hCc1pTQkpibU11TVNZd0pBWURWUVFMREIxQmNIQnNaU0JEWlhKMGFXWnBZMkYwYVc5dUlFRjFkR2h2Y21sMGVURXpNREVHQTFVRUF3d3FRWEJ3YkdVZ2FWUjFibVZ6SUZOMGIzSmxJRU5sY25ScFptbGpZWFJwYjI0Z1FYVjBhRzl5YVhSNU1CNFhEVEE1TURZeE5USXlNRFUxTmxvWERURTBNRFl4TkRJeU1EVTFObG93WkRFak1DRUdBMVVFQXd3YVVIVnlZMmhoYzJWU1pXTmxhWEIwUTJWeWRHbG1hV05oZEdVeEd6QVpCZ05WQkFzTUVrRndjR3hsSUdsVWRXNWxjeUJUZEc5eVpURVRNQkVHQTFVRUNnd0tRWEJ3YkdVZ1NXNWpMakVMTUFrR0ExVUVCaE1DVlZNd2daOHdEUVlKS29aSWh2Y05BUUVCQlFBRGdZMEFNSUdKQW9HQkFNclJqRjJjdDRJclNkaVRDaGFJMGc4cHd2L2NtSHM4cC9Sd1YvcnQvOTFYS1ZoTmw0WElCaW1LalFRTmZnSHNEczZ5anUrK0RyS0pFN3VLc3BoTWRkS1lmRkU1ckdYc0FkQkVqQndSSXhleFRldngzS
@zosiu
zosiu / note.rb
Created January 21, 2015 14:03
Association for polymorphic belongs_to of a particular type
class Note < ActiveRecord::Base
# The true polymorphic association
belongs_to :subject, polymorphic: true
# The trick to solve this problem
has_one :self_ref, class_name: self, foreign_key: :id
has_one :volunteer, through: :self_ref, source: :subject, source_type: Volunteer
has_one :participation, through: :self_ref, source: :subject, source_type: Participation
end
@zosiu
zosiu / api.rb
Created March 8, 2015 14:37
Grape setup with logging & documentation
module MyApp
module V1
class API < Grape::API
version 'v1', using: :path
format :json
before do
header['Access-Control-Allow-Origin'] = '*'
header['Access-Control-Request-Method'] = '*'
@zosiu
zosiu / pretty_git_log
Last active August 29, 2015 14:17
Pretty git log
git log --graph --pretty=format:'%C(auto)%h -%d %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit
@zosiu
zosiu / facebook_graph_api.rb
Last active January 10, 2017 16:23
Facebook Graph API w/ Koala
### app access token
graph = Koala::Facebook::OAuth.new APP_ID, APP_SECRET
graph.get_app_access_token # => APP_TOKEN
### create test users with permissions
test_users = Koala::Facebook::TestUsers.new app_id: APP_ID, secret: APP_SECRET
user = test_users.create true, 'email,user_birthday,user_posts', name: 'Bob'
# =>
# { "id" => USER_ID,
# "access_token" => USER_ACCESS_TOKEN,
-- cards are what you review. easy!
CREATE TABLE cards (
id integer primary key,
-- the epoch milliseconds of when the card was created
nid integer not null,
-- notes.id
did integer not null,
-- deck id (available in col table)
ord integer not null,
-- ordinal, seems like. for when a model has multiple templates, or thereabouts
@zosiu
zosiu / model.rb
Created March 31, 2015 09:39
has_many with date_part condition
# using the awesome squeel gem
has_many :shares, dependent: :destroy
has_many :stories, through: :shares
has_many(
:stories_this_month, -> do
where do
date_part('month', created_at).eq(Date.today.month) &
date_part('year', created_at).eq(Date.today.year)