Skip to content

Instantly share code, notes, and snippets.

@tgautier
tgautier / block_faker.rb
Created October 23, 2014 08:36
Faker method to illustrate blocks @lewagon
def fake_complexity(number)
puts "Launching very smart computation with the most clever algorithm...."
sleep(1)
puts ".."
sleep(1)
puts "...."
sleep(1)
puts "......."
result = yield(number, 4)
def greet(arg1, arg2, name)
puts "#{arg1} ---- #{arg2} #{yield(name)}"
end
me = 'John'
greet(1, 2, me) { |name| "Hello #{name}" }
greet(1, 2, me) { |name| "Bonjour #{name}" }
@tgautier
tgautier / file.json
Created October 24, 2014 09:25
[Le Wagon] JSON & Arrays
{
"name": "Paris",
"population": 2211000
}
--- a/hitcount/templatetags/hitcount_tags.py
+++ b/hitcount/templatetags/hitcount_tags.py
@@ -153,7 +153,7 @@ class GetHitCountJavascript(template.Node):
obj, created = HitCount.objects.get_or_create(content_type=ctype,
object_pk=object_pk)
- js = "$.post( '" + reverse('hitcount_update_ajax') + "'," + \
+ js = "jQuery.post( '" + reverse('hitcount_update_ajax') + "'," + \
"\n\t{ hitcount_pk : '" + str(obj.pk) + "' },\n" + \
"\tfunction(data, status) {\n" + \
from django.db.models.signals import post_init
def track_data(*fields):
"""
Tracks property changes on a model instance.
The changed list of properties is refreshed on model initialization
and save.
>>> @track_data('name')
@tgautier
tgautier / .gemrc
Last active September 26, 2015 23:17
My gemrc
---
:update_sources: true
:sources:
- https://rubygems.org
:benchmark: false
:bulk_threshold: 1000
:backtrace: false
:verbose: true
gem: --no-ri --no-rdoc
<div class="wide1_left">
<a class="sublime" href="{{ MEDIA_URL }}video/2day4ever_presentation.mp4">
<img src="{{ MEDIA_URL }}img/video_home.jpg" alt="Lancer la video" />
</a>
<video style="display:none" class="sublime zoom" width="800" height="450" preload="none">
<source src="{{ MEDIA_URL }}video/2day4ever_presentation.mp4" type='video/mp4'>
</video>
</div>
module Main where
type Radius = Double
type Side = Double
data Shape =
Point
| Circle Radius
| Rectangle Side Side
| Square Side
area Point
area (Circle r) =pi*r*r area (Rectangle w h) = w * h
require 'benchmark'
Benchmark.measure { Callbacks::ShoesProduct::Update.perform 29 }
# sibling_color_slug = {}
# variants_stock_availability = {}
# no specific update_siblings_of() for ShoesProduct
# sibling_ids: product.available_siblings.map(&:id),
# available: product.available?,
# displayable: product.displayable?,
# out_of_stock: product.out_of_stock?,
require 'singleton'
# outputs a colored call-trace graph to the Rails logger of the lines of ruby code
# invoked during a single request.
#
# Example:
#
# 1) Make sure this file is loaded in an initializer
#
# 2) Add the following to your application.rb in Rails3: