Skip to content

Instantly share code, notes, and snippets.

@inabhi9
inabhi9 / DottedExpandArray.php
Created September 1, 2013 06:40
Expand dotted array to multidimensional array.
<?php
class DottedExpandArray{
/* This class will expand dotted array to multidimensional array.
For eg,
array(
'fish.in.pond' => 'its there',
'fish.on.tree' => 'Not possible',
@inabhi9
inabhi9 / ExpandDottedArrayUsingJSON.php
Created September 6, 2013 17:14
Expand dotted 2D array to multidimensional array using JSON
<?php
function getDottedExpandedArray($array){
$finalArray = array();
foreach ($array as $key => $value) {
$sub_count = substr_count($key, '.')+1;
$json = '{"' . str_replace('.', '" : {"', $key);
$json .= '" : "'.$value.'"'.str_repeat('}', $sub_count);
$array = json_decode($json, true);
@inabhi9
inabhi9 / formencodeext.py
Created September 13, 2013 13:47
formencode additional extended validators
from formencode import FancyValidator, Invalid
import dateutil
import formencode
class validators:
class ISODateTime(FancyValidator):
"""
Validate and converts ISO formatted datetime string to python
datetime object
@inabhi9
inabhi9 / stripHTMLTags.js
Created October 9, 2013 12:52
Strip html tags from the given object, string or array
function stripHTMLTags(obj){
if (typeof(obj)=='string'){
var $temp = $('<div>'+obj+'</div>'); // if normal text
return $temp.text();
}
else if (typeof(obj)=='object'){
for (var k in obj){
obj[k] = stripHTMLTags(obj[k]);
}
return obj;
@inabhi9
inabhi9 / sendmail.php
Created October 29, 2013 07:47
PHP SendMail with reCaptcha
<?php
/* Simple script to send mail using php mail().
The content of the mail will generating by iterating each
key in $_POST variable.
If you want to verify captch please send reCAPTCHA='yes' in
request form
Response: It'll be in JSON containing two element.
'response' and 'msg'
@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.
@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 / 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 / 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()
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>