Skip to content

Instantly share code, notes, and snippets.

@HaiyangXu
HaiyangXu / Server.py
Created May 18, 2014 14:00
A simper python http server can handle mime type properly
# -*- coding: utf-8 -*-
#test on python 3.4 ,python of lower version has different module organization.
import http.server
from http.server import HTTPServer, BaseHTTPRequestHandler
import socketserver
PORT = 8080
Handler = http.server.SimpleHTTPRequestHandler
@shimarin
shimarin / block_device_sector_size.py
Last active January 11, 2024 13:24
Determining block device's sector size in Linux+Python
#!/usr/bin/python
import fcntl
import os
import struct
import array
import sys
BLKGETSIZE=0x1260
BLKGETSIZE64=0x80081272
BLKSSZGET=0x1268
@fliedonion
fliedonion / !GIST file list order - summary.md
Last active May 11, 2024 12:14
Understand GIST file list order.
Summary How to control (or Understand) your GIST page's files list order.
Notice not official documentation.
socat Examples
===============
* 注意
- SYSTEM で : を使う時は必ずエスケープすること
* 相手に接続
# telnet, netcat, socat それぞれの場合
$ socat - TCP:127.0.0.1:8000
@gbaman
gbaman / HowToOTG.md
Last active June 9, 2024 13:57
Simple guide for setting up OTG modes on the Raspberry Pi Zero

Raspberry Pi Zero OTG Mode

Simple guide for setting up OTG modes on the Raspberry Pi Zero - By Andrew Mulholland (gbaman).

The Raspberry Pi Zero (and model A and A+) support USB On The Go, given the processor is connected directly to the USB port, unlike on the B, B+ or Pi 2 B, which goes via a USB hub.
Because of this, if setup to, the Pi can act as a USB slave instead, providing virtual serial (a terminal), virtual ethernet, virtual mass storage device (pendrive) or even other virtual devices like HID, MIDI, or act as a virtual webcam!
It is important to note that, although the model A and A+ can support being a USB slave, they are missing the ID pin (is tied to ground internally) so are unable to dynamically switch between USB master/slave mode. As such, they default to USB master mode. There is no easy way to change this right now.
It is also important to note, that a USB to UART serial adapter is not needed for any of these guides, as may be documented elsewhere across the int

@sharow
sharow / monitoroff.py
Last active February 24, 2023 04:13
win: sleep monitor immediately
# -*- Mode: python; tab-width: 4; indent-tabs-mode: nil; coding: utf-8; -*-
from ctypes import *
user32 = WinDLL('User32')
DISPLAY_ON = -1
DISPLAY_OFF = 2
HWND_BROADCAST = 0xffff
WM_SYSCOMMAND = 0x0112
SC_MONITORPOWER = 0xf170
@somma
somma / create_process_as_login_user.cpp
Last active August 27, 2022 15:32
create_process_as_login_user
bool
create_process_as_login_user(
_In_ const wchar_t* cmdline
)
{
_ASSERTE(NULL != cmdline);
if (NULL == cmdline) return false;
DWORD session_id = WTSGetActiveConsoleSessionId();
DWORD explorer_pid = 0xFFFFFFFF;
@jamieweavis
jamieweavis / macos-app-icon.md
Last active May 30, 2024 18:05
How to create an .icns macOS app icon
@kgantsov
kgantsov / large_file_server.py
Created April 14, 2017 11:18
Example of serving large files using aiohttp server without reading entire file into a memory
import asyncio
import os
from aiohttp import web
from aiohttp import streamer
@streamer
async def file_sender(writer, file_path=None):
"""
@xuhang57
xuhang57 / nbd.sh
Created July 31, 2017 14:47
Build Network Block Device Kernel Module On CentOS7
uname -r
sudo su
# useradd builder
# groupadd builder
cd /home/centos
# Get Source Code
wget http://vault.centos.org/7.2.1511/updates/Source/SPackages/kernel-3.10.0-327.28.3.el7.src.rpm
rpm -ivh kernel-3.10.0-327.28.3.el7.src.rpm
# Build Preparation