Skip to content

Instantly share code, notes, and snippets.

View johndel's full-sized avatar
🖖

John Deliyiannis johndel

🖖
View GitHub Profile
@johndel
johndel / interfaces
Created June 9, 2014 17:48
Basic configuration for static ip
auto lo
iface lo inet loopback
auto eth0
iface eth0 inet static
address 192.168.1.51
netmask 255.255.255.0
gateway 192.168.1.1
dns-nameservers 8.8.8.8
@johndel
johndel / variables.css.scss
Created January 20, 2014 09:13
variables.css.scss example
// Colors
$base_color: #FFE403;
$base_hover_color: #FFFF00;
$second_color: #272727;
$second_hover_color: #555;
// Fonts
$font_one: 'Open Sans', sans-serif;
// Sprites
@johndel
johndel / front_base.css.scss
Last active January 3, 2016 18:39
front_base.css.scss
@import url(http://fonts.googleapis.com/css?family=Open+Sans:400,700,300&subset=latin,greek);
@import "compass";
@import "compass/utilities/sprites/base";
@import "font-awesome";
@import "front/variables";
@import "front/override";
@import "front/general";
@import "front/header";
@import "front/horizontal_menu";
@johndel
johndel / test.js
Created December 14, 2013 21:07
Test in my blog (http://johndel.gr) the automatic brief generator of an article. It uses the TextTeaser (http://www.textteaser.com/)
$.ajax({
url:"http://uncreative.korny.cc:8888/",
type: "POST",
data: JSON.stringify({
id: encodeURIComponent($('.post_title').text()),
title:$('.post_title').text(),
text:$('.post_content').text()
.replace(/[^"':;/!?.>,<\[\]{}\-=\+\(\)|!@#$%^&*~`\u2019\u201C\u201D\w]/g," ")
.replace(/([.,!?])[\s]*([^\s])/g,"$1 $2")
.replace(/\s+/g," ")
@johndel
johndel / slow_queries.rb
Last active December 29, 2015 14:28
A simple way to monitor your precious app. Put it inside the initializers and log valuable informations.
ActiveSupport::Notifications.subscribe "sql.active_record" do |name, started, finished, unique_id, data|
Thread.current["active_record_sql_count"] ||= 0
if data[:name].nil? || data[:name] != "SCHEMA"
Thread.current["active_record_sql_count"] = Thread.current["active_record_sql_count"] + 1
end
end
ActiveSupport::Notifications.subscribe "process_action.action_controller" do |name, started, finished, unique_id, data|
time = Time.now
slow_logfile = File.open(Rails.root.join("log", "slow.log"), 'a')
@johndel
johndel / fetcher.rb
Created November 23, 2013 18:10
Parse json and store the results to a database
require 'rubygems'
require 'json'
require 'httparty'
require 'active_record'
require 'pry'
ActiveRecord::Base.establish_connection(
:adapter => 'mysql2',
:database => 'lol',
:username => 'yourusername',
@johndel
johndel / complete.rb
Last active December 28, 2015 08:59
FQL test for fun complete.
require 'koala'
require 'pry'
require 'rubygems'
require 'selenium-webdriver'
require 'active_record'
ActiveRecord::Base.establish_connection(
:adapter => 'mysql2',
:database => 'test',
:username => 'whatever',
@johndel
johndel / gist:7473591
Last active December 28, 2015 08:39
Fql first attempt: Find TV shows with genre comedy through facebook pages.
require 'koala'
require 'rubygems'
require 'active_record'
ActiveRecord::Base.establish_connection(
:adapter => 'mysql2',
:database => 'test',
:username => 'whatever',
:password => 'whatever',
:host => 'localhost')
@johndel
johndel / omniauth_callbacks_controller.rb
Created July 20, 2013 18:33
omniauth_controller for multiple providers.
class OmniauthCallbacksController < Devise::OmniauthCallbacksController
def all
#raise request.env["omniauth.auth"].to_yaml
omniauth = request.env["omniauth.auth"]
provider = User.from_omniauth(omniauth)
if provider.persisted?
flash.notice = "Successful login"
sign_in(provider.user)
@after_sign_in_url = after_sign_in_path_for(provider.user)
@johndel
johndel / devise.rb
Created July 20, 2013 18:31
Multiple providers, one solution, generate password randomly.
def self.from_omniauth(auth)
unless provider = Provider.where(auth.slice(:provider, :uid)).first # New User
provider = Provider.new(provider: auth.provider, uid: auth.uid, oauth_token: auth.credentials.token)
user = User.where(email: auth.info.email).first # If user is already a devise user
if user.nil? # New user
random_password = (0...8).map{(65+rand(26)).chr}.join
user = User.create(email: auth.info.email, password: random_password, password_confirmation: random_password, confirmed_at: Time.now)
end
provider.user = user
end