Skip to content

Instantly share code, notes, and snippets.

View lym's full-sized avatar
🎾

salym lym

🎾
View GitHub Profile
@lym
lym / git-conventions.md
Created December 10, 2021 17:40 — forked from mhartington/git-conventions.md
Git Conventions

You've been working locally for awhile. You're ready to push some changes, but someone else pushed something! You have to pull in their changes before you can push yours.

git pull origin master forces you to create a merge commit, which is annoying.

Instead, do git pull --rebase origin master. This will effectively:

  1. Stash your changes
  2. Pull in the changes from origin
  3. Apply your changes on top

No merge commit!

@lym
lym / secret-key-gen.py
Created September 23, 2020 14:30 — forked from ndarville/secret-key-gen.py
Generating a properly secure SECRET_KEY in Django
"""
Two things are wrong with Django's default `SECRET_KEY` system:
1. It is not random but pseudo-random
2. It saves and displays the SECRET_KEY in `settings.py`
This snippet
1. uses `SystemRandom()` instead to generate a random key
2. saves a local `secret.txt`
@lym
lym / random_string_generator.rb
Created September 2, 2019 20:09 — forked from KamilLelonek/random_string_generator.rb
Ruby random string generator with particular length
class RandomStringGenerator
def without_numbers(length)
random_string(length, alphabet)
end
def with_numbers(length)
random_string(length, alphabet + numbers)
end
private
@lym
lym / gist:89a1dd28a8ca27e87c68d3325e7b0be6
Created November 28, 2018 13:52
[Fix] Headless::Exception: Display socket is taken but lock file is missing - check the Headless troubleshooting guide
mkdir /tmp/.X11-unix && sudo chmod 1777 /tmp/.X11-unix && sudo chown root /tmp/.X11-unix/
@lym
lym / macos-recovery-server.md
Created November 3, 2018 13:14
Fixing "The recovery server could not be contacted" in MacOS High Sierra

I was trying to reinstall High Sierra on an older MacBook Air using internet recovery and I kept on getting an error message when trying to reinstall High Sierra.

The recovery server could not be contacted

It appears that this has to do with the time on the machine not being synchronized, so when the MacBook tries to reach out to the recovery server the certificates do not validate and we get this useless error message.

To fix this.

  1. Open up a Terminal from the utilities menu
  2. Enter the following command
@lym
lym / capybara cheat sheet
Created April 18, 2018 11:41 — forked from zhengjia/capybara cheat sheet
capybara cheat sheet
=Navigating=
visit('/projects')
visit(post_comments_path(post))
=Clicking links and buttons=
click_link('id-of-link')
click_link('Link Text')
click_button('Save')
click('Link Text') # Click either a link or a button
click('Button Value')
@lym
lym / rubocop_pre_commit_hook
Created April 16, 2018 11:40 — forked from mpeteuil/rubocop_pre_commit_hook
Ruby style guide git pre-commit hook using Rubocop as the style guide checker. Only runs on staged ruby files that have been added and/or modified.
#!/usr/bin/env ruby
require 'english'
require 'rubocop'
ADDED_OR_MODIFIED = /A|AM|^M/.freeze
changed_files = `git status --porcelain`.split(/\n/).
select { |file_name_with_status|
file_name_with_status =~ ADDED_OR_MODIFIED
def _check_meter_image(self, meter_image): # meter_image is a base64-encoded string
err_msg = 'Please take a photograph of the meter'
if meter_image:
pre_img = base64.encodestring(bytearray(meter_image, 'utf8'))
pre_img2 = base64.decodestring(pre_img)
img_file = io.BytesIO(pre_img2)
img = Image.open(img_file)
print(img.filename)
if img.format == 'JPEG':
return True
@lym
lym / gist:456ec863d3fc3c63cab4
Created April 17, 2015 14:04
psycopg: Error: b'You need to install postgresql-server-dev-X.Y for building a server-side extension or libpq-dev for building a client-side application.\n'
# Just install libpq-dev
$ sudo apt-get install libpq-dev
@lym
lym / django_console
Created February 5, 2015 08:01
Start an interactive shell in a django project
# With manage.py
$ env/bin/python manage.py shell
# Without manage.py
$ export DJANGO_SETTINGS_MODULE=[module containing your settings]
$ env/bin/python
>>> import django
>>> django.setup()