Skip to content

Instantly share code, notes, and snippets.

View codeadict's full-sized avatar
🕸️
λ: f(f(state)) = f(state)

Dairon M. codeadict

🕸️
λ: f(f(state)) = f(state)
View GitHub Profile
@codeadict
codeadict / dabblet.css
Created June 21, 2012 17:57
Based on email I got from andrea ricci
/* Based on email I got from andrea ricci */
a[href^="mailto:"]:before { content: "\2709"; }
.phone:before { content: "\2706"; }
.important:before { content: "\27BD"; }
blockquote:before { content: "\275D"; }
blockquote:after { content: "\275E"; }
.alert:before { content: "\26A0"; }
:before, :after {
@codeadict
codeadict / Valida Cedula
Created June 24, 2013 13:55
Validar cedula Ecuatoriana en un form de DJANGO
def clean_cedula(self):
"""
Valída que sea Correcta la Cédula
"""
ced = self.cleaned_data['cedula']
msg = "La Cédula introducida no es válida"
valores = [ int(ced[x]) * (2 - x % 2) for x in range(9) ]
suma = sum(map(lambda x: x > 9 and x - 9 or x, valores))
veri = 10 - (suma - (10 * (suma / 10)))
if int(ced[9]) == int(str(veri)[-1:]):
@codeadict
codeadict / dabblet.css
Created October 28, 2013 22:13
A "deeper" indented text effect with the :before and :after pseudo-elements.
/**
* A "deeper" indented text effect with the :before and :after pseudo-elements.
*/
html, body {
height: 100%;
}
body {
margin: 0;
@codeadict
codeadict / helpers.py
Created August 28, 2014 16:54
Verificacion de RUCS y Cedulas Ecuador
def check_ruc_private(self, ruc):
"""
Aloritmo para verificar RUC de Empresa Privada.
"""
try:
if (int(ruc[0] + ruc[1])) < 23:
prueba1 = True
else:
prueba1 = False
@codeadict
codeadict / scp.py
Last active August 29, 2015 14:19
Store Credit Problem from Google Code Jam
def store_credit_problem(credit, items):
"""
@author: Dairon Medina <http://github.com/codeadict>
My python implementation for Store Credit Problem from Google Code Jam:
http://code.google.com/codejam/contest/351101/dashboard#s=p0
@param credit: integer representing store credit
@param items: list of product prices, must be integers
@returns: tuple with the two prices that consumes the whole credit
@codeadict
codeadict / import_models.rb
Created July 21, 2015 15:07
Importer Data structure
class DataImportTables < ActiveRecord::Migration
def change
create_table :imports do |t|
t.string :for_model, null: false, default: 'Properties'
t.string :name, null: false
t.attachment :file, null: false
t.references :company, null: false
t.timestamps null: false
end
@codeadict
codeadict / 20150806152332_property_status_history.rb
Created August 6, 2015 15:46
Migration for property status history
class PropertyStatusHistory < ActiveRecord::Migration
def change
create_table :property_history do |t|
t.references :property, index: true, null: false
t.references :user, null: false, index: true
t.string :status, null: false
t.datetime :datetime, null: false
end
end
end
@codeadict
codeadict / 20150928213406_add_us_states.rb
Created September 29, 2015 17:08
Rails migration that creates a table with all United States states and associated territories
class AddUsStates < ActiveRecord::Migration
def up
create_table :states do |t|
t.string :iso_abbr, unique: true
t.string :name
t.timestamps
end
#: insert states here
states_data = [
@codeadict
codeadict / gen_primes.py
Created September 29, 2015 17:29
Generates a list of prime numbers from 2 to N. Done for a friend homework of MIT edx.
def primesList(N):
"""
Generates a list of prime numbers from 2 to N.
N: an integer
"""
return [a for a in range(2, N) if not [b for b in range(2,a) if not a%b]]
def __main__():
print primesList(100)
@codeadict
codeadict / currify.py
Created October 6, 2015 05:13
My modest Python currying implementation using a decorator. Currying is a kind of incremental binding of function arguments.
def currify(func):
"""
Decorator to curry a function, use it like this:
>>> @currify
... def sum(a, b, c):
... return a + b + c
It works on normal way:
>>> sum(1, 2, 3)
6
And also binding the params: