Skip to content

Instantly share code, notes, and snippets.

View sourabhv's full-sized avatar

Sourabh Verma sourabhv

View GitHub Profile
var markdownIt = require('markdown-it')
function delim_plugin(md) {
// Insert each marker as a separate text token, and add it to delimiter list
//
function tokenize(state, silent) {
var i, scanned, token, len, ch,
start = state.pos,
marker = state.src.charCodeAt(start);
@sourabhv
sourabhv / wsl-vpn-net-fix.sh
Created August 18, 2022 22:46
Bash script to fix internet access in WSL2 via powershell when connected to VPN which changes network interface adapter (like Cisco AnyConnect)
#!/bin/bash
# MIT License
# -----------------------------------------------------------------------------
# Copyright 2022 Sourabh Verma
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
#!/bin/bash
set -eu
SENTRY_DOWNLOAD_Linux_i686="https://downloads.sentry-cdn.com/sentry-cli/1.37.4/sentry-cli-Linux-i686"
SENTRY_DOWNLOAD_Windows_x86_64="https://downloads.sentry-cdn.com/sentry-cli/1.37.4/sentry-cli-Windows-x86_64.exe"
SENTRY_DOWNLOAD_Darwin_x86_64="https://downloads.sentry-cdn.com/sentry-cli/1.37.4/sentry-cli-Darwin-x86_64"
SENTRY_DOWNLOAD_Linux_x86_64="https://downloads.sentry-cdn.com/sentry-cli/1.37.4/sentry-cli-Linux-x86_64"
SENTRY_DOWNLOAD_Windows_i686="https://downloads.sentry-cdn.com/sentry-cli/1.37.4/sentry-cli-Windows-i686.exe"
VERSION="1.38.0"
PLATFORM=`uname -s`

Keybase proof

I hereby claim:

  • I am sourabhv on github.
  • I am sourabhv (https://keybase.io/sourabhv) on keybase.
  • I have a public key ASDcNNUxAtMIPrgb6Vt-gd7PWl61zqV8XUnM06g9gM_H7Qo

To claim this, I am signing this object:

@sourabhv
sourabhv / JSONSerializer
Created October 18, 2013 17:08
Django JSONSerializer to serialize Django model's fields and properties into JSON
from StringIO import StringIO
from django.core.serializers.json import Serializer
class JSONSerializer(Serializer):
'''
JSON serialize to serialize db fields and properties
Example:
>>> JSONSerializer().serialize(Model.objects.all(), ('field1', 'field2',))
'''
@sourabhv
sourabhv / AddressRepository.java
Last active May 26, 2017 05:37
Repository Design Pattern in Android using RxJava, Retrofit, SQLBrite and SQLDelight Raw
public class AddressRepository implements BaseRepo<Address> {
private final RestApi mRestApi;
private final BriteDatabase mDatabase;
public AddressRepository(RestApi restApi, BriteDatabase database) {
mRestApi = restApi;
mDatabase = database;
}
@sourabhv
sourabhv / Address2.java
Last active May 26, 2017 05:32
Repository Design Pattern in Android using RxJava, Retrofit, SQLBrite and SQLDelight Raw
@AutoValue
public abstract class Address implements AddressModel, Parcelable {
public static final Factory<Address> FACTORY = new Factory<>(AutoValue_Address::new);
public static final Func1<Cursor, Address> MAPPER = FACTORY.selectAllMapper()::map;
public static Builder builder() {
return new AutoValue_Address.Builder();
}
@sourabhv
sourabhv / SqlBriteExample.java
Last active May 26, 2017 05:32
Repository Design Pattern in Android using RxJava, Retrofit, SQLBrite and SQLDelight Raw
SqlBrite sqlBrite = new SqlBrite.Builder().build();
BriteDatabase database = sqlBrite.wrapDatabaseHelper(openHelper, Schedulers.io());
// Insert transaction
Transaction transaction = database.newTransaction();
Address.InsertRow insertRow = new Address.InsertRow(database.getWritableDatabase());
try {
insertRow.bind(1, "Home", "House No. 42", "Foo Lane", null, "Gurgaon", "India", 123456);
database.executeInsert(Address.TABLE_NAME, insertRow.program);
@sourabhv
sourabhv / BaseRepository.java
Last active May 25, 2017 08:11
Repository Design Pattern in Android using RxJava, Retrofit, SQLBrite and SQLDelight
public interface BaseRepository<T> {
Observable<T> add(T item);
Observable<List<T>> add(List<T> items);
Observable<T> query(long id);
Observable<List<T>> query();
Observable<T> update(T item);
Observable<Integer> remove(T item);
}
@AutoValue
public abstract class Address implements AddressModel {
public static final Factory<Address> FACTORY = new Factory<>(new AddressModel.Creator<Address>() {
@Override
public Address create(long id, @NonNull String name, @NonNull String line1, @Nullable String line2, @Nullable String landmark, @NonNull String city, @NonNull String country, long pincode) {
return Address.builder()
.id(id)
.name(name)
.line1(line1)