Skip to content

Instantly share code, notes, and snippets.

View algotrader-dotcom's full-sized avatar

Mai_Xoa algotrader-dotcom

View GitHub Profile
@algotrader-dotcom
algotrader-dotcom / locustfile.py
Created August 9, 2018 03:10 — forked from acrollet/locustfile.py
Log in to Drupal 8 with locust.io
from locust import HttpLocust, TaskSet, task
from bs4 import BeautifulSoup
class WebsiteTasks(TaskSet):
def on_start(self):
"""
on_start is called when a Locust start before,
any task is scheduled
"""
self.login()
@algotrader-dotcom
algotrader-dotcom / Delete all content entities in Drupal 8
Last active June 10, 2018 05:37 — forked from Jaesin/delete_content_entities.d8.php
Delete all content entities in Drupal 8.
<?php
// Delete all nodes.
entity_delete_multiple('node', \Drupal::entityQuery('node')->execute());
// Delete all files.
entity_delete_multiple('file', \Drupal::entityQuery('file')->execute());
// Delete all taxonomy terms.
entity_delete_multiple('taxonomy_term', \Drupal::entityQuery('taxonomy_term')->execute());
<?php
use Drupal\node\Entity\Node;
/**
* Before attaching a term(s) to a term reference field,
* Must know:
* - field_example_name: the full name of the term reference field
* - tid: the term ID(s) to attach
*
* Keep in mind that this example uses Node::load()
@algotrader-dotcom
algotrader-dotcom / __INDEX.txt
Created May 31, 2018 22:10 — forked from facine/__INDEX.txt
Drupal 8 - Examples
# Taxonomy terms:
- https://gist.github.com/facine/35bb291811c146b6fc9e#file-create_taxonomy_term-php
# Menu links:
- https://gist.github.com/facine/35bb291811c146b6fc9e#file-create_menu_link-php
# File items:
- https://gist.github.com/facine/35bb291811c146b6fc9e#file-create_file-php
# Nodes:
@algotrader-dotcom
algotrader-dotcom / update-d8-node-save
Created May 31, 2018 22:10 — forked from batigolix/update-d8-node-save
Update drupal 8 node and save
use Drupal\node\Entity\Node;
function _svv_tools_set_author() {
$user = user_load_by_name('test');
$query = \Drupal::entityQuery('node');
$nids = $query->execute();
dd($nids);
foreach ($nids as $nid) {
$node = Node::load($nid);
$node->uid->value = $user->id();
@algotrader-dotcom
algotrader-dotcom / script.php
Created May 20, 2018 18:11 — forked from logii/script.php
Create A Node Programmatically on Drupal 8
<?php
use Drupal\Core\DrupalKernel;
use Symfony\Component\HttpFoundation\Request;
$autoloader = require_once 'autoload.php';
$kernel = new DrupalKernel('prod', $autoloader);
$request = Request::createFromGlobals();
$response = $kernel->handle($request);
@algotrader-dotcom
algotrader-dotcom / parser.py
Last active January 3, 2018 16:33 — forked from hreeder/parser.py
Python nginx Log Parser
#!/usr/bin/env python
import gzip
import os
import sys
import re
os.system("mkdir nginx-logs")
os.system("cp /var/log/nginx/* nginx-logs/")
INPUT_DIR = "nginx-logs"
@algotrader-dotcom
algotrader-dotcom / mongodb_playbook.yml
Created December 29, 2017 13:20 — forked from ferromir/mongodb_playbook.yml
Ansible Playbook to setup MongoDB on Ubuntu 14.04 (ubuntu/trusty64)
---
- hosts: all
sudo: true
vars:
mongodb_version: 3.0.7
tasks:
- name: MongoDB | Import the public key used by the package management system
apt_key: keyserver=keyserver.ubuntu.com id=7F0CEB10
- name: MongoDB | Create a list file
lineinfile: dest=/etc/apt/sources.list.d/mongodb-org-3.0.list line="deb http://repo.mongodb.org/apt/ubuntu precise/mongodb-org/3.0 multiverse" state=present create=yes
@algotrader-dotcom
algotrader-dotcom / curl.md
Created December 27, 2017 15:11 — forked from subfuzion/curl.md
curl POST examples

Common Options

-#, --progress-bar Make curl display a simple progress bar instead of the more informational standard meter.

-b, --cookie <name=data> Supply cookie with request. If no =, then specifies the cookie file to use (see -c).

-c, --cookie-jar <file name> File to save response cookies to.

@algotrader-dotcom
algotrader-dotcom / zabbix_agent_install.sh
Last active June 12, 2018 10:48 — forked from freeminder/zabbix_agent_install.sh
Zabbix Agent installation script
#!/bin/bash -e
if [ "$UID" -ne 0 ]; then
echo "Please run as root"
exit 1
fi
# Only run it if we can (ie. on Ubuntu/Debian)
if [ -x /usr/bin/apt-get ]; then
apt-get update