Skip to content

Instantly share code, notes, and snippets.

View devhero's full-sized avatar
😁

Andrea Parisi devhero

😁
  • devhero
  • Milan
View GitHub Profile
ifconfig | grep -E "([0-9]{1,3}\.){3}[0-9]{1,3}" | grep -v 127.0.0.1 | awk '{ print $2 }' | cut -f2 -d: | head -n1
from selenium.webdriver.support.ui import WebDriverWait # available since 2.4.0
from selenium.webdriver.support import expected_conditions as EC # available since 2.26.0
from selenium.webdriver.common.by import By
from selenium import webdriver
# API LIST
# http://seleniumhq.github.io/selenium/docs/api/py/api.html
# explicitly wait for the element to become present
wait = WebDriverWait(driver, 10)
import re
s = "ABC12DEF3G56HIJ7"
pattern = re.compile(r'([A-Z]+)([0-9]+)')
# all matches
for (letters, numbers) in re.findall(pattern, s):
print numbers, '*', letters
# It is better to use re.finditer if you dataset is large:
# The best way to customize your serialization is to get Django to serialize to Python dicts first. Then you can post-process those dicts however you like, before dumping them out to JSON:
from django.core import serializers
import json
# this gives you a list of dicts
raw_data = serializers.serialize('python', Phone.objects.all())
# now extract the inner `fields` dicts
actual_data = [d['fields'] for d in raw_data]
# and now dump to JSON
@devhero
devhero / lectures
Created May 31, 2016 07:36
lectures
https://blog.8thlight.com/uncle-bob/2012/08/13/the-clean-architecture.html
http://www.taimila.com/blog/ddd-and-testing-strategy/
Byobu is a suite of enhancements to tmux, as a command line
tool providing live system status, dynamic window management,
and some convenient keybindings:
F1 * Used by X11 *
Shift-F1 Display this help
F2 Create a new window
Shift-F2 Create a horizontal split
Ctrl-F2 Create a vertical split
Ctrl-Shift-F2 Create a new session
@devhero
devhero / sidekiqweb_password.rb
Created October 12, 2015 08:34
sidekiq web password protected
# routes.rb
require 'sidekiq'
require 'sidekiq/web'
Sidekiq::Web.use(Rack::Auth::Basic) do |user, password|
[user, password] == ["sidekiqadmin", "yourpassword"]
end
File.open(path, 'w') { |file| file.write("your text") }
2.0.0p0 :001 > require 'matrix'
=> true
2.0.0p0 :002 > m = Matrix[]
=> Matrix.empty(0, 0)
2.0.0p0 :003 > m = Matrix.rows(m.to_a << [1,2,3])
=> Matrix[[1, 2, 3]]
2.0.0p0 :004 > m = Matrix.rows(m.to_a << [2,3,4])
=> Matrix[[1, 2, 3], [2, 3, 4]]
Cut and paste:
Position the cursor where you want to begin cutting.
Press v to select characters (or uppercase V to select whole lines).
Move the cursor to the end of what you want to cut.
Press d to cut (or y to copy).
Move to where you would like to paste.
Press P to paste before the cursor, or p to paste after.
Copy and paste is performed with the same steps except for step 4 where you would press y instead of d: