Skip to content

Instantly share code, notes, and snippets.

View nikolaik's full-sized avatar
🤹‍♂️

Nikolai Røed Kristiansen nikolaik

🤹‍♂️
View GitHub Profile
@nikolaik
nikolaik / sentry-alert.py
Last active April 17, 2023 18:29
Sentry: Automate setup of alerting rules for a project
import argparse
import json
import os
import requests
ORG_SLUG = "..."
SLACK_WORKSPACE_ID = "..."
OWNER_TEAM = "..."
SLACK_RULES = {
@nikolaik
nikolaik / finn_app_script.js
Last active June 8, 2022 11:18
finn scraping
function fetchFinnData(finn_url) {
/** fetchFinnData('https://www.finn.no/realestate/homes/ad.html?finnkode=116229744'); */
if (!finn_url || finn_url.indexOf('?finnkode=') === -1) {
return;
}
var API_URL = 'https://<YOUR_HEROKU_APP>.herokuapp.com/'
var param = finn_url.match(/\?finnkode=.+/)[0]
var url = API_URL + param;
var response = UrlFetchApp.fetch(url, {'muteHttpExceptions': true});
@nikolaik
nikolaik / backends.py
Created November 3, 2014 22:36
django-auth-ldap email or username authentication
from django_auth_ldap.backend import LDAPBackend, _LDAPUser
class LDAPUsernameBackend(LDAPBackend):
settings_prefix = "AUTH_LDAP_U_"
class LDAPEmailBackend(LDAPBackend):
settings_prefix = "AUTH_LDAP_E_"
@nikolaik
nikolaik / bot.py
Created December 14, 2018 13:32
mock example
import requests
def call_api(text):
print('calling example.com')
return requests.post('http://example.com', data=text).text
def translate_bot():
texts = ['jeg', 'vet', 'ikke', 'hvordan', 'dette', 'fungerer']
return all(['Example' not in call_api(t) for t in texts])
@nikolaik
nikolaik / finn_real_estate_ad.json
Last active April 22, 2018 16:10
finn.no scraping
{
"ad": {
"Boligtype": "Leilighet",
"Bruksareal": 37,
"Bruttoareal": 42,
"Byggeår": 1939,
"Eieform": "Andel",
"Energimerking": "D - gul",
"Etasje": "4.",
"Fellesformue": 46513,
@nikolaik
nikolaik / get_releases.sh
Created September 11, 2014 13:59
Use puppetmaster to fetch facts (JSON) from all puppet nodes without puppetdb
#!/bin/bash
NODES=`sudo puppet cert list --all|awk '{print $2}'` # Get all node names
echo '{"facts": [' > facts_tmp.json
# for node in node: get facts
echo -n $NODES | xargs -d " " -i sh -c 'sudo puppet facts find {} --terminus rest | tr "\n" "," >> facts_tmp.json'
sed -ie 's/,$//' facts_tmp.json # Remove last comma
echo ']}' >> facts_tmp.json
# optionally format and filter json (requires jq)
#!/usr/bin/env python3
"""
wp_upgrade.py upgrades wordpress installations recursively.
- looks for Wordpress installations
- tries to update WP core, plugins and themes
Requires: WP-CLI http://wp-cli.org/
"""

Keybase proof

I hereby claim:

  • I am nikolaik on github.
  • I am nikolaik (https://keybase.io/nikolaik) on keybase.
  • I have a public key ASC81RvUb8Mz8F7pr6Amv-ExoL3H6DRvNL1tB67mM06EHAo

To claim this, I am signing this object:

#!/usr/bin/env python3
# coding: utf-8
import os
from subprocess import Popen, PIPE
import shutil
# SETTINGS
CERT_DIR = '/etc/nginx/ssl/'
WEBROOT = '/tmp/letsencrypt'
@nikolaik
nikolaik / jpg_to_webp.sh
Created October 27, 2013 15:43
Converts a directory of .jpgs to .webp
find . -name "*.jpg" -print0 | sed 's/\.jpg//g' | xargs -0 -I % cwebp -o %.webp -q 90 %.jpg