Skip to content

Instantly share code, notes, and snippets.

View xdays's full-sized avatar
🏠
Working from home

Xiangjun Zhang xdays

🏠
Working from home
View GitHub Profile
@actuino
actuino / HowToOTG.md
Created February 10, 2017 09:23 — forked from gbaman/HowToOTG.md
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

@titpetric
titpetric / purge-multi.lua
Created January 8, 2017 18:34
Delete NGINX cached items with a PURGE with wildcard support
-- Tit Petric, Monotek d.o.o., Tue 03 Jan 2017 06:54:56 PM CET
--
-- Delete nginx cached assets with a PURGE request against an endpoint
-- supports extended regular expression PURGE requests (/upload/.*)
--
function file_exists(name)
local f = io.open(name, "r")
if f~=nil then io.close(f) return true else return false end
end
@gene1wood
gene1wood / role_arn_to_session.py
Created December 29, 2016 17:38
Simple python function to assume an AWS IAM Role from a role ARN and return a boto3 session object
import boto3
def role_arn_to_session(**args):
"""
Usage :
session = role_arn_to_session(
RoleArn='arn:aws:iam::012345678901:role/example-role',
RoleSessionName='ExampleSessionName')
client = session.client('sqs')
"""
@jerel
jerel / seed.ex
Created December 19, 2016 15:48
Run seeds in an Elixir Distillery app
defmodule :release_tasks do
def seed do
:ok = Application.load(:myapp)
[:postgrex, :ecto, :logger]
|> Enum.each(&Application.ensure_all_started/1)
Myapp.Repo.start_link
@ilude
ilude / KVM Attempt 1
Last active June 12, 2023 18:58
KVM virt-install command
qemu-img create -f qcow2 /pool/vms/xp.qcow2 50G
sudo virt-install --connect qemu:///system -n xp -r 512 --disk path=/pool/vms/xp.qcow2,size=50 \
-c /pool/iso/windows/en_windows_xp_professional_with_service_pack_3_x86_cd_vl_x14-73974.iso \
--graphics vnc,listen=0.0.0.0,port=65322 --noautoconsole \
--os-type windows --os-variant winxp
@nextrevision
nextrevision / deleteJenkinsJobs.groovy
Created December 3, 2015 17:30
Groovy script to delete all jenkins jobs that match a regex pattern
import jenkins.model.*
def matchedJobs = Jenkins.instance.items.findAll { job ->
job.name =~ /my_regex_here/
}
matchedJobs.each { job ->
println job.name
//job.delete()
}
@bhameyie
bhameyie / haproxy.cfg
Last active November 28, 2023 22:30
Sample haproxy config
##based on Mesosphere Marathon's servicerouter.py haproxy config
global
daemon
log 127.0.0.1 local0
log 127.0.0.1 local1 notice
maxconn 4096
tune.ssl.default-dh-param 2048
defaults
@sh4t
sh4t / flush_chrome_dns.sh
Last active April 4, 2023 09:42
clearing chrome dns cache and sockets via js
#!/bin/bash
#
# The MIT License (MIT)
# Copyright (c) 2015 Justin Shattuck <shat@f5.com>, F5 Networks, Inc.
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
@eweitz
eweitz / http_debugging.py
Last active November 12, 2022 20:32 — forked from tonetheman/http_debugging.py
Debug requests for urllib in Python 3
"""" Tested in Python 3.4 """
import urllib.request
import http.client
http.client.HTTPConnection.debuglevel = 1
response = urllib.request.urlopen('https://github.com/eweitz')
@yunano
yunano / consul.service
Created May 1, 2015 15:52
/etc/systemd/system/consul.service
[Unit]
Description=consul agent
Requires=network-online.target
After=network-online.target
[Service]
EnvironmentFile=-/etc/sysconfig/consul
Environment=GOMAXPROCS=2
Restart=on-failure
ExecStart=/usr/local/sbin/consul agent $OPTIONS -config-dir=/etc/consul.d