This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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'); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$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>'; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$current_uri = \Drupal::request()->getRequestUri(); |