Skip to content

Instantly share code, notes, and snippets.

View swistak's full-sized avatar

Marcin Raczkowski swistak

  • Poland, Kraków
View GitHub Profile
@swistak
swistak / Usefull.css
Last active September 28, 2015 07:49
Usefull css classes
// Cross browser way to split very long words into multiple lines.
// From https://justmarkup.com/log/2015/07/31/dealing-with-long-words-in-css/?mc_cid=ce70bb0280&mc_eid=da0b57a173
.hyphenate {
overflow-wrap: break-word;
word-wrap: break-word;
-webkit-hyphens: auto;
-ms-hyphens: auto;
-moz-hyphens: auto;
hyphens: auto;
# Example nginx + git HTTP Smart mode (git-http-backend) + HTTP Authentication + HTTPS redirect
# jeroen@massar.ch - http://jeroen.massar.ch
server {
listen 192.0.1.1:80;
listen [2001:db8::1]:80;
# Redirect all non-HTTPS traffic to the HTTPS variant
return 301 https://$host$request_uri;
}
@swistak
swistak / paranoia.rb
Last active August 29, 2015 13:57
Acts as Paranoid / Paranoia implementation for rails 4
# Copy of Paranoia gem without default_scope, which cannot be removed for assotiations
# in Rails 3.0. Refactored to use ActiveSupport::Concern, as it's only one file and don't need
# separate vendor/plugin.
module Paranoia
extend ::ActiveSupport::Concern
included do
scope :deleted, ->{ where.not(deleted_at: nil) }
scope :visible, ->{ where(deleted_at: nil) }
end
@swistak
swistak / example_notification.json
Last active April 29, 2019 21:39
SNS in Rails
{
"Type" : "SubscriptionConfirmation",
"MessageId" : "0941b7b3-4797-44e5-8079-dbf8ef09793f",
"Token" : "2336412f37fb687f5d51e6e241d164b0533302ec696efc8f113cd2252ce8a925c1e44a3c4ca2984675da85b9bd8c05da85337beb1f24a9c659b22ed3a8cc682f3457c4ead28d392a40e5c35c0e9>
"TopicArn" : "arn:aws:sns:us-west-2:164053224164:email-list",
"Message" : "You have chosen to subscribe to the topic arn:aws:sns:us-west-2:164053224164:email-list.\nTo confirm the subscription, visit the SubscribeURL included in this message",
"SubscribeURL" : "https://sns.us-west-2.amazonaws.com/?Action=ConfirmSubscription&TopicArn=arn:aws:sns:us-west-2:164053224164:email-list&Token=REDACTED",
"Timestamp" : "2013-10-05T17:00:04.135Z",
"SignatureVersion" : "1",
"Signature" : "<REDACTED>"
require 'fileutils'
require 'logger'
require 'erb'
# Pdf generation service based on wkhtmltopdf.
class PdfGenerator
class WkhtmltopdfError < RuntimeError; end
DPI = 96 # Pixels in inch
@swistak
swistak / oauth_test.rb
Last active December 25, 2015 13:19
Test script for ePaństwo Paszport.
require 'sinatra'
require 'oauth2'
require 'json'
require 'logger'
require 'pp'
set :port, 3000
site = ARGV[0] || 'http://paszport.epf.org.pl/'
callback_host = ARGV[1] || 'http://localhost:3000'
@swistak
swistak / bee.rb
Last active December 19, 2015 06:09
Working bee.
# Helpful reference http://alexpeattie.com/blog/working-with-dates-in-git/
require 'date'
require 'pp'
cmd="git log --author='#{ARGV[0]}' --abbrev-commit --format=medium --date=iso"
cmd+= " --since=#{Date.parse(ARGV[1]).to_s}" if ARGV[1]
cmd+= " --until=#{Date.parse(ARGV[2]).to_s}" if ARGV[2]
e = e = <<GIT
@swistak
swistak / generate_savon_objects.rb
Last active July 3, 2018 03:36
Generates objects for use with Savon. Uses Action Model (ServiceBase) to provide validations and attributes access, but can be easily adapted to Struct / OpenStruct if needed.
module MyModule
# Regenerating code
end unless __FILE__ == $0
if __FILE__ == $0
require 'savon'
split_on = "#" + " Regenerating code"
code = File.read(__FILE__).split(split_on).last
wsdl_file_path = File.join(File.dirname(__FILE__), ARGV.first || raise("Gimme file!"))
@swistak
swistak / ihn_email.rb
Created September 17, 2012 11:21
Hacker news API test
require 'open-uri'
require 'json'
require 'ostruct'
require 'mail' # you need to `gem install mail`
# Retrieval
print "Connecting to api.ihackernews.com ... "; $stdout.flush
home_page = open('http://api.ihackernews.com/page').read
puts "done."
@swistak
swistak / install.sh
Last active October 5, 2015 10:47
Configuration for server with ultra fast depoys
aptitude install build-essential openssl libreadline6 libreadline6-dev curl git-core zlib1g zlib1g-dev libssl-dev libyaml-dev libsqlite3-dev sqlite3 libxml2-dev libxslt-dev autoconf libc6-dev ncurses-dev automake libtool bison git pwgen vim libcurl4-openssl-dev
chmod 777 /opt
adduser www
su www
cd ~
curl -L get.rvm.io | bash -s stable