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 / hackerrank - Sock Merchant - python3
Created November 9, 2018 10:12
hackerrank - Sock Merchant - python3
#!/bin/python3
import sys
n = 10
arr = [1, 1, 3, 1, 2, 1, 3, 3, 3, 3 ]
arr_m = {}
def calculatePairs(a,arr):
match_count = 0
for item in arr:
To make the change for one session, use this command:
:set tabstop=4
To make the change permanent, add it to ~/.vimrc or ~/.vim/vimrc:
set tabstop=4
Ansible playbook to setup HTTPS using Let's encrypt on nginx.
The Ansible playbook installs everything needed to serve static files from a nginx server over HTTPS.
The server pass A rating on [SSL Labs](https://www.ssllabs.com/).
To use:
1. Install [Ansible](https://www.ansible.com/)
2. Setup an Ubuntu 16.04 server accessible over ssh
3. Create `/etc/ansible/hosts` according to template below and change example.com to your domain
4. Copy the rest of the files to an empty directory (`playbook.yml` in the root of that folder and the rest in the `templates` subfolder)
@algotrader-dotcom
algotrader-dotcom / basicSelect.php
Created September 24, 2018 03:33 — forked from basdenooijer/basicSelect.php
Solarium select examples
<?php
// A query without any settings will use default values.
// This will result in a "*:*" query, 10 rows, all fields.
$query = new Solarium_Query_Select;
$result = $client->select($query);
echo 'Number of results found: ' . $result->getNumFound();
// The resultset is iterable, you could also use $result->getDocuments() to get an array with documents.
@algotrader-dotcom
algotrader-dotcom / monitor_cve.py
Created August 18, 2018 02:19 — forked from PaulSec/monitor_cve.py
Monitors @cvenew and sends me a message on Telegram if a keyword triggers
from tweepy import StreamListener
from tweepy import Stream
import tweepy
import json
import telebot
import requests
CONSUMER_KEY = 'XXXXXXXXXXXXXXXXXXXXXXX'
CONSUMER_SECRET = 'XXXXXXXXXXXXXXXXXXXXXXX'
ACCESS_KEY = 'XXXXXXXXXXXXXXXXXXXXXXX'
@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 / Drupal 8 : Static db query
Created June 11, 2018 17:21
Drupal 8 : Static db query
<?php /* Main */
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 / Drupal 8 : Render view programmatically
Last active June 11, 2018 02:50
Drupal 8 : Render view programmatically
<?php
$id = 'a';
$view = \Drupal\views\Views::getView('glossary');
$view->setDisplay('default');
$view->setArguments([$id]);
$view->execute();
$results = $view->result;
foreach($results as $result){
$nid = $result->nid;
$node_storage = \Drupal::entityTypeManager()->getStorage('node');
@algotrader-dotcom
algotrader-dotcom / Drupal 8: Query all contents with title startwith a letter
Created June 11, 2018 02:48
Drupal 8: Query all contents with title startwith a letter
$content = '<ul>';
$first_char = 'a';
$query = \Drupal::entityQuery('node');
$query->condition('title', '%'.$first_char.'%','LIKE');
$query->range(0,25);
$nids = $query->execute();
$node_storage = \Drupal::entityTypeManager()->getStorage('node')->loadMultiple($nids);
foreach ($node_storage as $node){
$content = $content.'<li>'.$node->title->value.'</li>';
@algotrader-dotcom
algotrader-dotcom / Drupal 8: Get current URI
Created June 11, 2018 02:46
Drupal 8: Get current URI
$current_uri = \Drupal::request()->getRequestUri();