Skip to content

Instantly share code, notes, and snippets.

View Pk13055's full-sized avatar
🇦🇪
Focusing

Pk13055

🇦🇪
Focusing
View GitHub Profile
##
## tinyproxy.conf -- tinyproxy daemon configuration file
##
## This example tinyproxy.conf file contains example settings
## with explanations in comments. For decriptions of all
## parameters, see the tinproxy.conf(5) manual page.
##
#
# User/Group: This allows you to set the user and group that will be
@Pk13055
Pk13055 / location.py
Created May 11, 2018 14:35
Django generic location model compatible with Google MapsAPI
class Location(models.Model):
id = models.AutoField(primary_key=True)
place_id = models.CharField(max_length=128, unique=True, editable=False) # used to reference the place using maps API
name = models.CharField(max_length=100) # can be used for object referral
full_name = models.CharField(max_length=200) # can be used to display
extra = models.CharField(max_length=50, null=True, blank=True) # can be used to store door no, and other info
lat = models.DecimalField(max_digits=8, decimal_places=5)
long = models.DecimalField(max_digits=8, decimal_places=5)
@Pk13055
Pk13055 / brightness.sh
Created May 9, 2018 01:19
script to replace in-place for brightness control
#! /bin/bash
cd "/usr/local/lib/brightnessctl"
source configuration.sh
if [ -z "$1" ]
then
value=`cat $brightFolder"max_brightness"`
elif [ "$1" -lt "100" ]
then
value="100"
@Pk13055
Pk13055 / validate.py
Created May 4, 2018 13:56
How-to: Custom validation for Django models
class Family(models.Model):
id = models.AutoField(primary_key=True)
child = models.ForeignKey(Child, on_delete=models.DO_NOTHING)
parent = models.ForeignKey(Parent, on_delete, models.DO_NOTHING)
def clean(self, *args, **kwargs):
error_msg = "%s error | %s"
if not all([_ in Feedback.cat_keys.keys for _ in self.categories]):
raise ValidationError({ 'categories' : error_msg % ("Keys", "Invalid Keys")})
@Pk13055
Pk13055 / save_from_console.js
Created April 16, 2018 23:27
Save JSON obejcts from the (Firefox) console to storage.
(function(console){
console.save = function(data, filename){
if(!data) {
console.error('Console.save: No data')
return;
}
if(!filename) filename = 'console.json'
@Pk13055
Pk13055 / perdelta.py
Created April 1, 2018 05:04
Generate a list of dates/times/datetimes
def perdelta(start, end, delta):
'''
function that generates a list of date/time/datetime
'''
t = 'datetime'
if isinstance(start, datetime.time):
start = datetime.datetime.combine(datetime.datetime.now().date(), start)
end = datetime.datetime.combine(datetime.datetime.now().date(), end)
t = 'time'
elif isinstance(start, datetime.date):
@Pk13055
Pk13055 / nginx-tuning.md
Created March 23, 2018 17:33 — forked from denji/nginx-tuning.md
NGINX tuning for best performance

NGINX Tuning For Best Performance

For this configuration you can use web server you like, i decided, because i work mostly with it to use nginx.

Generally, properly configured nginx can handle up to 400K to 500K requests per second (clustered), most what i saw is 50K to 80K (non-clustered) requests per second and 30% CPU load, course, this was 2 x Intel Xeon with HyperThreading enabled, but it can work without problem on slower machines.

You must understand that this config is used in testing environment and not in production so you will need to find a way to implement most of those features best possible for your servers.

@Pk13055
Pk13055 / wpa_supplicant.conf
Created March 8, 2018 21:09
wpa supplicant configuration for raspberry pi WiFi connection
# interfaces(5) file used by ifup(8) and ifdown(8)
# Please note that this file is written to be used with dhcpcd
# For static IP, consult /etc/dhcpcd.conf and 'man dhcpcd.conf'
# Include files from /etc/network/interfaces.d:
source-directory /etc/network/interfaces.d
auto lo iface lo inet loopback
iface eth0 inet dhcp
allow-hotplug wlan0 auto
wlan0 iface wlan0 inet dhcp
wpa-ssid "essid" # replace with e-ssid
@Pk13055
Pk13055 / vpn.sh
Last active March 6, 2018 12:00
Script to switch on/off VPN/other connections
#!/bin/bash
if [ -z "$1" ]
then
status='up';
else
if [ "$1" == "list" ]
then
nmcli connection show && exit 0;
else
@Pk13055
Pk13055 / nginxproxy.md
Created January 20, 2018 22:38 — forked from soheilhy/nginxproxy.md
How to proxy web apps using nginx?

Virtual Hosts on nginx (CSC309)

When hosting our web applications, we often have one public IP address (i.e., an IP address visible to the outside world) using which we want to host multiple web apps. For example, one may wants to host three different web apps respectively for example1.com, example2.com, and example1.com/images on the same machine using a single IP address.

How can we do that? Well, the good news is Internet browsers