Skip to content

Instantly share code, notes, and snippets.

View edmon1024's full-sized avatar
💭
hello world!!!

Edmundo Andrade edmon1024

💭
hello world!!!
View GitHub Profile
@edmon1024
edmon1024 / admin.py
Created December 1, 2021 19:00 — forked from cansadadeserfeliz/admin.py
Django: validate inline form in main form
from django.contrib import admin
from product.forms import EquipmentForm
@admin.register(Equipment)
class EquipmentAdmin(admin.ModelAdmin):
form = EquipmentForm
inlines = [
EquipmentGalleryInline,
@edmon1024
edmon1024 / xiaomi_dns_block.lst
Created January 19, 2021 23:58
PiHole DNS Blocklist Xiaomi
# This is a DNS blocklist for the PiHole (https://pi-hole.net/) to block unnecessary connections to Xiaomi.
#
# License: GPL-3.0-or-later
#
# New Git Repo https://github.com/unknownFalleN/xiaomi-dns-blocklist
# There I will also add further lists e.g. all subdomains.
# Please use the list from the new repo, I will not maintain both lists and delete them here sometime
#
# Please help to collect domains!
groups:
- name: datetime
rules:
- record: daily_saving_time_belgium
expr: |
(vector(0) and (month() < 3 or month() > 10))
or
(vector(1) and (month() > 3 and month() < 10))
or
(
@edmon1024
edmon1024 / gist:c96c831a3a6b4042c35bc4bb3690cfd4
Created February 5, 2019 03:11 — forked from thinkphp/gist:5110833
Creating sha-1 on Node.js.
var crypto = require('crypto');
function sha1( data ) {
var generator = crypto.createHash('sha1');
generator.update( data )
return generator.digest('hex')
}
console.log( sha1('adrian') )
@edmon1024
edmon1024 / basic_auth_nodejs_test.js
Created February 5, 2019 03:10 — forked from charlesdaniel/basic_auth_nodejs_test.js
Example of HTTP Basic Auth in NodeJS
var http = require('http');
var server = http.createServer(function(req, res) {
// console.log(req); // debug dump the request
// If they pass in a basic auth credential it'll be in a header called "Authorization" (note NodeJS lowercases the names of headers in its request object)
var auth = req.headers['authorization']; // auth is in base64(username:password) so we need to decode the base64
console.log("Authorization Header is: ", auth);
@edmon1024
edmon1024 / joins.py
Created January 28, 2019 10:53 — forked from nickretallack/joins.py
How do I do a join without a real foreign key constraint?
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy import Column, ForeignKey, Integer, String, ForeignKeyConstraint
from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker, relationship
Model = declarative_base()
class Parent(Model):
__tablename__ = 'parent'
id = Column(Integer, primary_key=True)
@edmon1024
edmon1024 / M2M_Association_SQLalchemy.py
Created January 28, 2019 10:52 — forked from SuryaSankar/M2M_Association_SQLalchemy.py
An example of a many to many relation via Association Object in SQLAlchemy
import sqlalchemy
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy import Column, Integer, String, ForeignKey
from sqlalchemy.orm import sessionmaker, relationship, backref
from sqlalchemy.ext.associationproxy import association_proxy
import uuid
engine = sqlalchemy.create_engine('sqlite:///:memory:')
Base = declarative_base()
@edmon1024
edmon1024 / main.yaml
Created January 24, 2019 19:50 — forked from kbariotis/main.yaml
Ansible playbook for deploying a Node.js app to DigitalOcean
- name: DO
hosts: localhost
vars:
project_name: "PUT A NAME FOR YOUR PROJECT HERE"
do_token: "PUT YOUR DIGITAL OCEAN API KEY HERE ==> https://cloud.digitalocean.com/settings/api/tokens"
repository: "PUT YOUR REPOSITORY URL HERE"
tasks:
- name: LOCAL | Generate SSH key
shell: ssh-keygen -b 2048 -t rsa -f ~/.ssh/{{project_name}} -q -N ""
@edmon1024
edmon1024 / node-exporter
Last active February 13, 2019 09:24 — forked from wallentx/node-exporter
node-exporter init script for Amazon AMI/RHEL to be used with systemv. Place in /etc/init.d/ and ensure that line 12 matches your path
#!/bin/bash
#
#
#
# Start on runlevels 3, 4 and 5. Start late, kill early.
# chkconfig: 345 95 05
#
#
#!/bin/bash
@edmon1024
edmon1024 / read-access.sql
Created January 3, 2019 17:53 — forked from oinopion/read-access.sql
How to create read only user in PostgreSQL
-- Create a group
CREATE ROLE readaccess;
-- Grant access to existing tables
GRANT USAGE ON SCHEMA public TO readaccess;
GRANT SELECT ON ALL TABLES IN SCHEMA public TO readaccess;
-- Grant access to future tables
ALTER DEFAULT PRIVILEGES IN SCHEMA public GRANT SELECT ON TABLES TO readaccess;