Skip to content

Instantly share code, notes, and snippets.

@inabhi9
inabhi9 / machine.js
Created October 12, 2021 13:51
Generated by XState Viz: https://xstate.js.org/viz
// Available variables:
// - Machine
// - interpret
// - assign
// - send
// - sendParent
// - spawn
// - raise
// - actions
@inabhi9
inabhi9 / lte.php
Created July 12, 2018 08:25
PHP script to switch Huawei Airtel dongle to NDIS mode in pfsense
#!/usr/local/bin/php-cgi -f
<?php
sleep(5);
$cnt = 0;
$hw_addr = "$MAC_ADDRESS";
$found_hw = false;
// call usb mode switch
$cmd = 'timeout 7 /usr/local/sbin/usb_modeswitch -c /usr/local/share/usb_modeswitch/12d1:1f01 -v 12d1 -p 1f01 > /var/log/usb_modeswitch.log';
@inabhi9
inabhi9 / cloning-macOS-from-linux.md
Last active April 4, 2017 14:12
Cloning MacOS X from Linux

Cloning MacOS X from Linux

BACKUP

First we save the GUID (Globally Unique Identifier) Partition Table (GPT), so that we can restore the same partition table on the target machine. We use the commandline version of gdisk for this, named sgdisk

sgdisk --backup=/srv/macos/parttable.gpt.sgdisk /dev/sda
@inabhi9
inabhi9 / harvest_widget_gitlab.js
Last active May 28, 2019 11:53
Harvest widget for Gitlab
// Grab JS injection chrome extension
// https://chrome.google.com/webstore/detail/custom-javascript-for-web/poakhlngfciodnhlhhgnaaelnpjljija
// For Gitlab v11
(function () {
var itemName = document.querySelector('.breadcrumbs-sub-title').innerText + ' - ' + document.querySelector('h2.title').innerText,
_url = document.head.querySelector("[property='og:url']").content.split('/'),
itemId = _url.slice(3).join('/'),
baseUrl = _url.slice(0, 3).join('/'),
dataItem = {id: itemId, name: itemName};
@inabhi9
inabhi9 / ansible-playbook-wrapper.py
Last active July 22, 2016 12:49
wrapper to find Ansible project's root path. Useful when you can't change working directory to run playbook
#!/usr/bin/python
import sys
import os
from subprocess import call
ansible_args = sys.argv[1:]
# Finding playbook file arg
try:
ansible_playbook = [arg for arg in ansible_args if '.yml' in arg][0]
UseCanonicalName Off
DocumentRoot "/var/www/vhosts/example-wildcard"
<Directory "/var/www/vhosts/example-wildcard">
Options FollowSymLinks
AllowOverride All
Order allow,deny
Allow from all
</Directory>
@inabhi9
inabhi9 / split_vcard.py
Created September 4, 2014 12:10
Split single vCard to multiple vcards
#!/usr/bin/python
cnt = 0
o = None
with open('/tmp/00001.vcf') as f:
for l in f.readlines():
if 'BEGIN:VCARD' in l:
o = open('/tmp/contacts/%s.vcf' % cnt, 'w')
o.write(l)
if 'END:VCARD' in l:
o.close()
@inabhi9
inabhi9 / luup_ac_control.lua
Created August 2, 2014 14:22
Control AC using Virtual Thermostat temperature
-- Get Virtual Thermostat here: http://forum.micasaverde.com/index.php?topic=8363.0
local lul_vdev_thermostat = 48
local lul_dev_sensor = 43
local lul_dev_ac = 37
local DEFAULT_COOL_SP = 26
-- Desired temperature mode in Virtual Thermostate
local modeStatus = luup.variable_get ("urn:upnp-org:serviceId:HVAC_UserOperatingMode1", "ModeStatus", lul_vdev_thermostat)
-- Desired temperature set in Virtual Thermostate
local coolSp = tonumber (luup.variable_get ("urn:upnp-org:serviceId:TemperatureSetpoint1_Cool", "CurrentSetpoint", lul_vdev_thermostat), 10) or DEFAULT_COOL_SP
@inabhi9
inabhi9 / mtsbalace.php
Created July 9, 2014 12:53
Get MTS 3g prepaid balance
<?php
function formatSizeUnits($bytes) {
if ($bytes >= 1073741824) {
$bytes = number_format($bytes / 1073741824, 2) . ' GB';
} elseif ($bytes >= 1048576) {
$bytes = number_format($bytes / 1048576, 2) . ' MB';
} elseif ($bytes >= 1024) {
$bytes = number_format($bytes / 1024, 2) . ' KB';
} elseif ($bytes > 1) {
$bytes = $bytes . ' bytes';
@inabhi9
inabhi9 / async_receiver.py
Last active May 10, 2023 10:56
Django async receiver decorator using Celery
from django.dispatch.dispatcher import Signal
from celery import shared_task
# Warning. Monkey patch.
# in the kwargs signal recievers are passed an instance of django.display.dispatcher.Signal and
# this contains an instance of threading.Lock - an object that can't be pickled.
# This leads me to the monkey patch that was shown at the start of this article which
# simply adds a __reduce__ method to the Signal class that alters the pickle behaviour and only
# pickles the provided_args property of the Signal instance.