Skip to content

Instantly share code, notes, and snippets.

@ilfuriano
ilfuriano / fix-wsl2-dns-resolution
Created December 22, 2022 10:19 — forked from coltenkrauter/fix-wsl2-dns-resolution
Fix DNS resolution in WSL2
More recent resolution:
1. cd ~/../../etc (go to etc folder in WSL).
2. echo "[network]" | sudo tee wsl.conf (Create wsl.conf file and add the first line).
3. echo "generateResolvConf = false" | sudo tee -a wsl.conf (Append wsl.conf the next line).
4. wsl --terminate Debian (Terminate WSL in Windows cmd, in case is Ubuntu not Debian).
5. cd ~/../../etc (go to etc folder in WSL).
6. sudo rm -Rf resolv.conf (Delete the resolv.conf file).
7. In windows cmd, ps or terminal with the vpn connected do: Get-NetIPInterface or ipconfig /all for get the dns primary and
secondary.
@ilfuriano
ilfuriano / android_studio_live_template
Created February 2, 2021 08:09
Live Template for Android Studio
// create backing field for live date (ex. in ViewModel)
private val _$VARIABLE_NAME$ = MutableLiveData<$VARIABLE_TYPE$>()
val $VARIABLE_NAME$: LiveData<$VARIABLE_TYPE$> = _$VARIABLE_NAME$
@ilfuriano
ilfuriano / EventObserver.kt
Created January 23, 2021 15:21 — forked from JoseAlcerreca/EventObserver.kt
An Observer for Events, simplifying the pattern of checking if the Event's content has already been handled.
/**
* An [Observer] for [Event]s, simplifying the pattern of checking if the [Event]'s content has
* already been handled.
*
* [onEventUnhandledContent] is *only* called if the [Event]'s contents has not been handled.
*/
class EventObserver<T>(private val onEventUnhandledContent: (T) -> Unit) : Observer<Event<T>> {
override fun onChanged(event: Event<T>?) {
event?.getContentIfNotHandled()?.let { value ->
onEventUnhandledContent(value)
@ilfuriano
ilfuriano / Event.kt
Created January 23, 2021 15:20 — forked from JoseAlcerreca/Event.kt
An event wrapper for data that is exposed via a LiveData that represents an event.
/**
* Used as a wrapper for data that is exposed via a LiveData that represents an event.
*/
open class Event<out T>(private val content: T) {
var hasBeenHandled = false
private set // Allow external read but not write
/**
* Returns the content and prevents its use again.
@ilfuriano
ilfuriano / MainActivity.kt
Created February 6, 2020 14:30
Clear focus for EditText on click outside
class MainActivity : AppCompatActivity() {
// code
// Clear focus for EditText on click outside
override fun dispatchTouchEvent(ev: MotionEvent?): Boolean {
if (ev?.action == MotionEvent.ACTION_DOWN) {
(currentFocus as? EditText)?.let { et ->
Rect().also { rect ->
et.getGlobalVisibleRect(rect)
@ilfuriano
ilfuriano / backup_db.sh
Created September 13, 2017 18:07
Backup Postgres DB to Google Drive
#!/bin/bash
now=`date +%Y%m%d-%H%M%S`
day_ago=7
db_name="DB_NAME"
base_path="BASE_PATH"
dump_fpath="$base_path/backup_db-$now.sql.gz"
sudo -u postgres pg_dump $db_name | gzip -9 > $dump_fpath
@ilfuriano
ilfuriano / hgignore.LaTeX
Last active September 11, 2015 08:17 — forked from bertvv/hgignore.LaTeX
Ignore temporary files for a LaTeX project in Mercurial. Works as well as a .gitignore for a Git repository if you drop the line with "syntax: glob".
# Files to ignore in a LaTeX project
syntax: glob
# General files to ignore
*~
*.bak
# Mac os
.DS_Store
@ilfuriano
ilfuriano / comma_separated_email_field.py
Last active August 29, 2015 14:14
Validate form field that include email or emails separated by 'token' kwargs, by default ',' a comma. Return a list [] of email(s). Check validity of the email(s) from django EmailField regex (work with 1.6)
from django import forms
from django.utils.translation import ugettext_lazy as _
from django.core import validators
from django.core.validators import EMPTY_VALUES
from django.forms.fields import Field
# Same as https://djangosnippets.org/snippets/3012/ but compatible with Django 1.6
class CommaSeparatedEmailField(Field):
description = _(u"E-mail address(es)")