Skip to content

Instantly share code, notes, and snippets.

View VehpuS's full-sized avatar
🦔

Moshe Jonathan Gordon Radian VehpuS

🦔
View GitHub Profile
// set location of docx text content file
$xmlFile = $targetDir."/word/document.xml";
$reader = new XMLReader;
$reader->open($xmlFile);
// set up variables for formatting
$text = ''; $formatting['bold'] = 'closed'; $formatting['italic'] = 'closed'; $formatting['underline'] = 'closed'; $formatting['header'] = 0;
// loop through docx xml dom
while ($reader->read()){
@VehpuS
VehpuS / extendable_proxy_class.py
Created August 31, 2016 14:53
Extendable Proxy Class - a class that behaves like another class, but can be extended with attributes / methods as needed.
# Proxy class created by "tomer filiba" at http://code.activestate.com/recipes/496741-object-proxying/
class Proxy(object):
__slots__ = ["_obj", "__weakref__"]
def __init__(self, obj):
object.__setattr__(self, "_obj", obj)
#
# proxying (special cases)
#
def __getattribute__(self, name):
return getattr(object.__getattribute__(self, "_obj"), name)
@VehpuS
VehpuS / chromeExtensionFacebookSend.js
Created November 28, 2017 02:11
A function that allows a chrome extension to create a Facebook send message window with a pre-filled message, logging that message to the extension's console.
const sendMessage = (recipientID, link, message) => {
const url = ("http://www.facebook.com/dialog/send?" +
"app_id=" + appId +
"&link=" + encodeURI(link) +
"&to=" + recipientID +
"&display=popup" +
"&redirect_uri=" + encodeURI(link));
chrome.tabs.create({ url }, (tab) => {
const msg_val = 'document.querySelector("#feedform_user_message").value';
chrome.tabs.executeScript(tab.id, {
@VehpuS
VehpuS / dns_server.py
Created December 11, 2017 16:38
Based on https://github.com/samuelcolvin/dnserver - a DNS server in python with convenient parameters, and lots of documentation - for use and learning.
#!/usr/local/bin/python3
# -*- python -*-
'''
Owner : Moshe J. Gordon Radian
Description : DNS utilities using dnslib.
Based on: https://github.com/samuelcolvin/dnserver
Some resources about DNS:
- http://www.slashroot.in/what-dns-zone-file-complete-tutorial-zone-file-and-its-contents
- https://computer.howstuffworks.com/dns.htm
@VehpuS
VehpuS / bit_index_string.c
Last active May 10, 2018 07:44
OutstandingSmartArtificialintelligence created by VehpuS - https://repl.it/@VehpuS/OutstandingSmartArtificialintelligence
#include <stdio.h>
char txt[] = {
[(0 << 0) ... ((1 << 0) - 1)] = '0',
[(1 << 0) ... ((1 << 1) - 1)] = '1',
[(1 << 1) ... ((1 << 2) - 1)] = '2',
[(1 << 2) ... ((1 << 3) - 1)] = '3',
[(1 << 3) ... ((1 << 4) - 1)] = '4',
[(1 << 4) ... ((1 << 5) - 1)] = '5',
'\0'
<!DOCTYPE html>
<html>
<head>
<style>
.item1 {
grid-area: myArea;
}
.grid-container {
display: grid;
grid-template-areas:
#include <stdio.h>
// https://gcc.gnu.org/onlinedocs/cpp/Concatenation.html
#define test(a) b ## a
int main(void) {
char* bc = "Hello World\n";
printf(test(c));
return 0;
}
@VehpuS
VehpuS / struct-packed-bits.c
Last active October 22, 2018 19:53
reading packed struct bits created by VehpuS - https://repl.it/@VehpuS/reading-packed-struct-bits
#include <stdio.h>
#include <stdint.h>
typedef struct __attribute__((__packed__)) data_block_t {
uint8_t a;
uint8_t b : 1;
uint8_t c : 1;
uint8_t d : 1;
uint8_t e : 1;
uint8_t f : 1;
import requests # pip install requests
from functools import reduce
import json
from pprint import pprint, pformat
def create_mlnx_os_session(switch_ip, user_name, password, https=True, verify=False):
'''
@summary:
Using the requests library create a session with a MLNX-OS running machine, that can serve both web and JSON requests
@param switch_ip:
@VehpuS
VehpuS / c_csv_python_parser.c
Created February 8, 2019 23:51
A CSV parser in C using the Python csv standard module
#include <Python.h>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#define bail_null(obj) \
if (NULL == obj) { err = 1; goto bail; }
#define bail_require(cond) \
if (!(cond)) { err = 1; goto bail; }