Skip to content

Instantly share code, notes, and snippets.

View veelenga's full-sized avatar
🇺🇦
Annihilating code

Vitalii Elenhaupt veelenga

🇺🇦
Annihilating code
View GitHub Profile
@lucassus
lucassus / listeners_controller.rb
Created February 3, 2013 12:03
Paypal ipn listener
class ListenersController < ApplicationController
def paypal_ipn
raw_post = request.raw_post
notification = ActiveMerchant::Billing::Integrations::Paypal::Notification.new(raw_post)
@ipn_log = PaypalIpnLog.new(:raw_post => raw_post)
if development? || notification.acknowledge
recurring_payment_id = notification.params['recurring_payment_id']
@ipn_log.recurring_payment_id = recurring_payment_id
@wader
wader / gist:1232562
Created September 21, 2011 16:32
Paperclip migration rename, add and remove helpers
class UserRenameAvatarToProfileRemoveAAddB < ActiveRecord::Migration
# you may want to change these
AttachmentColumns = [["file_name", :string], ["content_type", :string], ["file_size", :integer]]
# make sure this matches your setup, also have a look in the rename and remove methods
AttachmentPath = Rails.root.join("public", "system")
def self.rename_attachment(table, old, new)
AttachmentColumns.each do |suffix, type|
rename_column table, "#{old}_#{suffix}", "#{new}_#{suffix}"
end
@TheSeamau5
TheSeamau5 / shuffleList.elm
Created January 18, 2015 02:11
Function to shuffle a list (useful to shuffle cards for example)
import List (..)
import Random (..)
import Text (asText)
shuffle : List a -> List a
shuffle lt =
let len = length lt
fgen = float 0 1
lgen = list len fgen
rlist = fst <| generate lgen (initialSeed 31415)
@serek
serek / migration.rb
Created April 22, 2010 13:15 — forked from firebelly/paperclip_migrations.rb
Migration from attachment_fu to paperclip.
class ConvertImagesToPaperclip < ActiveRecord::Migration
include PaperclipMigrations
def self.up
# Paperclip
add_column :images, :data_file_name, :string
add_column :images, :data_content_type, :string
add_column :images, :data_file_size, :integer
add_column :images, :data_updated_at, :datetime
@bmarini
bmarini / progress_bar.rb
Created September 14, 2011 21:55
CLI progress bar in ruby
class ProgressBar
def initialize(units=60)
@units = units.to_f
end
def print(completed, total)
norm = 1.0 / (total / @units)
progress = (completed * norm).ceil
pending = @units - progress
Kernel.print "[#{'=' * progress }#{' ' * ( pending )}] #{percentage(completed, total)}%\r"
@christhekeele
christhekeele / prime.ex
Last active May 5, 2017 10:54
Infinite Prime Generator in Elixir
# Elixir v1.0.2
defmodule Prime do
def stream do
Stream.unfold( [], fn primes ->
next = next_prime(primes)
{ next, [next | primes] }
end )
end
@gilbertw1
gilbertw1 / keybinds.el
Last active July 5, 2017 07:33
spacemacs keybinds
(evil-define-operator evil-delete-char-without-register (beg end type reg)
"delete character without yanking unless in visual mode"
:motion evil-forward-char
(interactive "<R><y>")
(if (evil-visual-state-p)
(evil-delete beg end type reg)
(evil-delete beg end type ?_)))
(evil-define-operator evil-delete-backward-char-without-register (beg end type reg)
"delete backward character without yanking"
@hugoabonizio
hugoabonizio / program.cr
Last active November 10, 2017 12:06
This program breaks Crystal compiler
a = {1, 0}
b = {a, a}
c = {b, b}
d = {c, c}
e = {d, d}
f = {e, e}
g = {f, f}
h = {g, g}
i = {h, h}
j = {i, i}
@postmodern
postmodern / rails_sqli.rb
Last active December 1, 2017 11:49
Proof-of-Concept exploit for Rails SQL Injection (CVE-2013-0156)
#!/usr/bin/env ruby
#
# Proof-of-Concept exploit for Rails SQL Injection (CVE-2013-0156)
#
# ## Advisory
#
# https://groups.google.com/forum/#!topic/rubyonrails-security/61bkgvnSGTQ/discussion
#
# ## Caveats
#
@faustinoaq
faustinoaq / reload.md
Last active December 6, 2017 03:15
Guide to reload client on public file changes.

Amber Reload

Reloading public files on Amber.

Requisites

You need Crystal and Amber::CMD installed

Steps