Skip to content

Instantly share code, notes, and snippets.

@aidvu
aidvu / Makefile
Last active March 21, 2023 21:06
Modify ping reply TTL with XDP
KDIR ?= /lib/modules/$(shell uname -r)
SDIR ?= $(KDIR)/source
CLANG ?= clang
LLC ?= llc
#ARCH := $(subst x86_64,x86,$(shell arch))
ARCH := x86
BIN := modify-ping-ttl.o
CLANG_FLAGS = -I. -I$(SDIR)/arch/$(ARCH)/include \
-I$(SDIR)/arch/$(ARCH)/include/generated \
@aidvu
aidvu / commands.sh
Last active May 6, 2022 11:21
Shell commands
# Remove deleted or moved files from `svn`:
svn status --ignore-externals | grep ! | tr -s ' ' | cut -d ' ' -f2 | xargs svn rm
# Get contents of file from line 5 to line 13:
sed -n -e 5,13p [FILE]
# Find all .php files and search/replace string
find -name "*.php" -not -path ".svn" -print | xargs grep -l "require_lib( 'old' )" | xargs -I X sed -i -e "s|require_lib( 'old' )|require_lib( 'new' )|g" X
# Execute a command in every folder in current directory
find . -maxdepth 1 -type d \( ! -name . \) -exec bash -c "cd {} && pwd" \;
# OpenWRT cron for switching changing LED color if pinging 8.8.8.8 fails
ping -q -c 5 8.8.8.8 && { echo 0 > /sys/devices/platform/gpio-leds/leds/inet:orange/brightness; echo 255 > /sys/devices/platform/gpio-leds/leds/inet:blue/brightness; } || { echo 255 > /sys/devices/platform/gpio-leds/leds/inet:orange/brightness; echo 0 > /sys/devices/platform/gpio-leds/leds/inet:blue/brightness; }
@aidvu
aidvu / language_extract.sh
Created January 15, 2015 20:26
SugarCRM Language Files Extractor
#!/bin/bash
echo "This script copies SugarCRM translation files for given language code from current directory to destination directory"
echo ""
echo "Enter language code:"
read language
echo "Enter destination directory:"
read destination_dir
rsync -uavm --include="*/" --include="*$language*" --exclude="*" . $destination_dir/$language
@aidvu
aidvu / freedns.afraid.org-sync.sh
Last active August 29, 2015 14:13
freedns.afraid.org
#!/bin/bash
current_wifi=`nmcli dev wifi | grep yes | cut -d\' -f2`;
home_wifi="{HOME_SSID}";
if [ "$current_wifi" == "$home_wifi" ]; then
wget -O - http://freedns.afraid.org/dynamic/update.php?{KEY} >> /tmp/freedns.afraid.org.log 2>&1 &
fi
@aidvu
aidvu / fstab
Last active August 29, 2015 14:12
/etc/fstab
# SSD
UUID=16aba771-3dca-4855-8678-7556fbc87fe1 / ext4 discard,noatime,errors=remount-ro 0 1
# swap
UUID=68de305b-931e-497a-ae96-2504ec4e161b none swap sw 0 0
# /tmp /var/tmp on RAM
tmpfs /tmp tmpfs defaults,noatime,mode=1777 0 0
tmpfs /var/tmp tmpfs defaults,noatime,mode=1777 0 0
# /var/log on HDD
UUID=73d1b2d3-8a9b-4a78-8418-01a46d85e226 /var/log ext4 defaults,noatime 0 2
# /var/www on HDD
@aidvu
aidvu / composer.json
Last active August 29, 2015 14:02
Wordpress/Redis
{
"require": {
"predis/predis": "dev-master"
}
}
@aidvu
aidvu / inverse.php
Created May 30, 2014 11:48
iconv/mb_convert_encoding
<?php
$text = '₩';
$fromEncoding = 'UTF-8';
$toEncoding = 'EUC-KR';
echo iconv($toEncoding, $fromEncoding, iconv($fromEncoding, $toEncoding, $text));
echo "\n";
echo mb_convert_encoding(mb_convert_encoding($text, $toEncoding, $fromEncoding), $fromEncoding, $toEncoding);
echo "\n";
@aidvu
aidvu / config.ini
Last active December 20, 2015 22:39
Backup MySQL dump to Dropbox using Python API
[backup]
access_token: {token}
from_dir: {from_dir}
to_dir: {to_dir}
file_types: {file_types}
@aidvu
aidvu / soap.php
Last active December 18, 2015 09:29
SugarCRM Soap
<?php
$_sessionId = null;
$_sc = new SoapClient(
null,
array(
'location' =>'http://127.0.0.1/6_5_x/ent/sugarcrm/soap.php',
'uri' => 'http://www.sugarcrm.com/sugarcrm',
'trace' => true,
@aidvu
aidvu / rest.php
Last active December 11, 2015 20:39
Get Emails related to a given Account, REST
<?php
$method = 'login';
$parameters = array('user_auth' => array('user_name' => 'admin', 'password' => md5('admin')));
$response = makeRESTCall($method, $parameters);
$session = $response['id'];
$method = 'get_relationships';
$relationship = 'email_addresses';
$module = 'Accounts';