Skip to content

Instantly share code, notes, and snippets.

@dmasotti
dmasotti / DetectPhoneCallState.md
Created November 23, 2022 14:09 — forked from er-abhishek-luthra/DetectPhoneCallState.md
DetectPhoneCallState.md

PhoneCallReceiver

Due to the design of Android, PhoneCallReceiver have to be a BroadcastReceiver. It can’t be a reciever registered with one app because the receiver may be run without our app being run, so we’d have to register in manifest. But I want the heavy lifting to be done by a library class(which we will be creating below)- I just want to derive from something and override a few functions. So ideally we have something like:

public abstract class PhonecallReceiver extends BroadcastReceiver {
protected void onIncomingCallStarted(Context ctx, String number, Date start);
protected void onOutgoingCallStarted(Context ctx, String number, Date start);
@dmasotti
dmasotti / virtualbox-vagrant-nuclear-option.sh
Created November 12, 2022 16:32 — forked from tjbenton/virtualbox-vagrant-nuclear-option.sh
Completely uninstall VirtualBox and Vagrant and reinstall through brew
# update brew because `brew update` is broken after updating to El Capitan
cd `brew --prefix`
git fetch origin
git reset --hard origin/master
sudo shutdown -r now # restart the computer
# open terminal and run the following
brew update
brew cleanup
@dmasotti
dmasotti / braket.ipynb
Created November 2, 2022 08:06 — forked from sametz/braket.ipynb
Dirac notation (bra/ket) LaTeX commands for use in Jupyter notebooks
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@dmasotti
dmasotti / AdbCommands
Created October 18, 2022 13:20 — forked from Pulimet/AdbCommands
Adb useful commands list
adb help // List all comands
== Adb Server
adb kill-server
adb start-server
== Adb Reboot
adb reboot
adb reboot recovery
adb reboot-bootloader
@dmasotti
dmasotti / VPNIKEv2Setup.swift
Created October 18, 2022 13:19 — forked from IhorYachmenov/VPNIKEv2Setup.swift
Example how configure VPN profile based on IKEv2 protocol use NEVPNManager with certificate authentication, example was be tested on real devices, server use AlgoVPN.
import Foundation
import NetworkExtension
class VPNIKEv2Setup {
static let shared = VPNIKEv2Setup()
let vpnManager = NEVPNManager.shared()
func initVPNTunnelProviderManager() {
@dmasotti
dmasotti / IPSecDemo.m
Created June 27, 2022 14:31 — forked from hongru/IPSecDemo.m
Start IPSec programmatically in iOS 8
- (void)viewDidLoad
{
[super viewDidLoad];
// init VPN manager
self.vpnManager = [NEVPNManager sharedManager];
// load config from perference
[_vpnManager loadFromPreferencesWithCompletionHandler:^(NSError *error) {
@dmasotti
dmasotti / column_builder.dart
Created April 29, 2020 12:32 — forked from slightfoot/column_builder.dart
Column Builder for Flutter. Can be used instead of a ListView with shrinkWrap.
class ColumnBuilder extends StatelessWidget {
final IndexedWidgetBuilder itemBuilder;
final MainAxisAlignment mainAxisAlignment;
final MainAxisSize mainAxisSize;
final CrossAxisAlignment crossAxisAlignment;
final TextDirection textDirection;
final VerticalDirection verticalDirection;
final int itemCount;
/**
* Register Custom myCRED Hook
* @since 1.0
* @version 1.0
*/
add_filter( 'mycred_setup_hooks', 'mycred_register_learndash_hook' );
function mycred_register_learndash_hook( $installed ) {
$installed['hook_learndash'] = array(
'title' => __( 'LearnDash' ),
@dmasotti
dmasotti / ld_woosubs_course_access.php
Created February 24, 2020 13:12 — forked from ThomasLeCoz/ld_woosubs_course_access.php
Functions to give or remove access to LearnDash courses
// Remove Access to the course linked to the subscription key
function remove_course_access( $user_id, $subscription_key ) {
// Get the course ID related to the subscription
$subscription = WC_Subscriptions_Manager::get_subscription( $subscription_key );
$courses_id = get_post_meta($subscription['product_id'], '_related_course', true);
// Update access to the courses
if ($courses_id && is_array($courses_id)) {
foreach ($courses_id as $course_id) {
@dmasotti
dmasotti / get_all_users_id_with_custom_subscription_level.php
Created February 24, 2020 13:10 — forked from mahfelwp/get_all_users_id_with_custom_subscription_level.php
Get all users id with custom subscription(membership) level
<?php
function get_all_users_id_by_membership_level_id() {
$memberships = rcp_get_memberships( array(
'status' => 'active',
'object_id' => 2 // Membership Levels ID
) );
foreach ($memberships as $membership) {