Skip to content

Instantly share code, notes, and snippets.

View johndel's full-sized avatar
🖖

John Deliyiannis johndel

🖖
View GitHub Profile
@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 / 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 / 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 / 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 / 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 / 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 / cagniotte.rb
Created July 12, 2014 08:10
Calculation of cagniotte
bet1 = 2.25
bet2 = 3.15
bet3 = 3.15
puts "#{(1 - 1/(1/bet1 + 1/bet2 + 1/bet3)) * 100}%"
#!/usr/bin/ruby
require 'aws-sdk'
require 'mail'
# The filename for using it during the script and the location
filename = "#{Time.now.to_s.split(" ").first}_data_only_dump.sql"
store_location = "/home/your_user/your_backups/#{filename}"
# Local backup of a postgres database
`pg_dump -U your_user your_db_name -f #{store_location} --data-only`
.groups{ng_repeat: "row in [] | skip_range:0:keyword_groups.length-1:3"}
.group{ng_repeat: "keyword_group in [] | range:row*3:((row+1)*3)-1:keyword_groups"}
@johndel
johndel / monitrc
Created October 3, 2014 14:40
monitrc basic file
set daemon 30
set logfile /var/log/monit.log
set idfile /var/lib/monit/id
set statefile /var/lib/monit/state
set eventqueue
basedir /var/lib/monit/events # set the base directory where events will be stored
slots 100 # optionally limit the queue siz
set httpd port 2812
allow 0.0.0.0/0.0.0.0
allow username:password