Skip to content

Instantly share code, notes, and snippets.

View innatewonderer's full-sized avatar

JZ innatewonderer

View GitHub Profile
@innatewonderer
innatewonderer / 0_reuse_code.js
Last active August 29, 2015 14:14
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@innatewonderer
innatewonderer / foo.rb
Last active August 29, 2015 14:08
include and getting access to attributes
class Foo
include PaymentContext
def initialize
@user_name = "New Foo User"
end
end
# http://api.rubyonrails.org/classes/ActiveRecord/Callbacks.html
# are hooks into the life cycle of an Active Record object that allow you to trigger logic
# before or after or around an alteration of the object state.
# types:
## method reference (symbol)
class User < ActiveRecord::Base
before_destroy :deactivate_payment_methods
has_many :payment_methods
@innatewonderer
innatewonderer / validations.rb
Last active August 29, 2015 14:08
Active Record validations
# http://guides.rubyonrails.org/active_record_validations.html
# ensure that only valid data is saved into the database
# comes in forms of:
## database constraints
## client-side validations
## controller-level validations
# conditional validations
class Order < ActiveRecord::Base
validates :card_number, presence: true, if: :paid_with_card?
@innatewonderer
innatewonderer / lib.text
Last active August 29, 2015 14:08
Rails folders
# what should go into your app's bin folder?
# http://reefpoints.dockyard.com/ruby/2012/02/14/love-your-lib-directory.html
# What it's not :
## it's not a dump
## it's not an initializer
# What it is:
## "Application specific libraries. Basically, any kind of custom code that
## doesn’t belong under controllers, models, or helpers. This directory is in the load path."
#!/usr/bin/env python2
"""
Author: takeshix <takeshix@adversec.com>
PoC code for CVE-2014-0160. Original PoC by Jared Stafford (jspenguin@jspenguin.org).
Supportes all versions of TLS and has STARTTLS support for SMTP,POP3,IMAP,FTP and XMPP.
"""
import sys,struct,socket
from argparse import ArgumentParser
@innatewonderer
innatewonderer / Gemfile
Last active August 29, 2015 13:57
return_json Sinatra App, deployed to Heroku
source 'https://rubygems.org'
gem 'sinatra'
gem 'json'
@innatewonderer
innatewonderer / gist:5287080
Last active December 15, 2015 16:09 — forked from sstephenson/gist:1120938
rbenv setup?
# Clone rbenv into ~/.rbenv
git clone git@github.com:sstephenson/rbenv.git ~/.rbenv
# Add rbenv to your PATH
# NOTE: rbenv is *NOT* compatible with rvm, so you'll need to
# remove rvm from your profile if it's present. (This is because
# rvm overrides the `gem` command.)
echo 'export PATH="$HOME/.rbenv/bin:$HOME/.rbenv/shims:$PATH"' >> ~/.bash_profile
exec $SHELL
@innatewonderer
innatewonderer / Ruby
Last active December 11, 2015 17:39
Trie in Ruby
#Understainding Trie in Ruby
#source https://github.com/kanwei/algorithms/blob/81987340f24edb7fd8ca60885b1f04d1907f8c03/lib/containers/trie.rb
=begin rdoc
A Trie is a data structure that stores key value pairs in a tree-like fashion. It allows
O(m) lookup speed, where m is the length of the key searched, and has no chance of collisions,
unlike hash tables. Because of its nature, search misses are quickly detected.
Tries are often used for longest prefix algorithms, wildcard matching, and can be used to
implement a radix sort.