Skip to content

Instantly share code, notes, and snippets.

View jhammann's full-sized avatar
👐

Jeroen Hammann jhammann

👐
View GitHub Profile
@jhammann
jhammann / jsonview-night-owl.css
Created August 9, 2019 14:15
The Night Owl theme for the JSONView chrome extension.
body {
white-space: pre;
font-family: monospace;
background-color: #011627;
color: #d6deeb;
}
.property {
font-weight: bold;
color: #7fdbca;
@jhammann
jhammann / vue-slugify-mixin.js
Created May 3, 2019 10:16
A Vue mixin to slugify strings.
Vue.mixin({
methods: {
slugify(string) {
if (typeof string !== 'undefined') {
return string.toLowerCase()
.replace(/[^\w ]+/g, '')
.replace(/ +/g, '_');
}
return string;
@jhammann
jhammann / nos-dark.user.css
Last active September 18, 2018 13:09
A dark user style for the NOS website.
/* ==UserStyle==
@name NOS Dark
@namespace https://gist.github.com/jhammann/
@version 0.1.2
==/UserStyle== */
@-moz-document domain("nos.nl") {
body,
body.homepage #most_viewed_videos,
#menu-nieuws,
@jhammann
jhammann / imei-input.js
Last active August 9, 2018 09:26
📲 Generate and fill in IMEI numbers automatically based on the input's id, class or name attribute.
[].forEach.call(document.querySelectorAll('input'), function(el) {
el.addEventListener('click', function() {
//Check the attributes to see if one of them contains IMEI.
var classes = el.getAttribute('class');
var id = el.getAttribute('id');
var name = el.getAttribute('name');
var attrStr = [classes, id, name].join(' ').toLowerCase();
if (attrStr.indexOf('imei') > -1) {
el.value = generateImei();
@jhammann
jhammann / geocode.js
Last active August 9, 2018 09:25
🗺 Geocode Google Spreadsheet Cells which uses OSM Nominatim.
function geocodeSelectedCells() {
var sheet = SpreadsheetApp.getActiveSheet();
var cells = sheet.getActiveRange();
if (cells.getNumColumns() != 4) {
Logger.log("Must select the Street, City, Lat and Lng columns.");
return;
}
var streetColumn = 1;
@jhammann
jhammann / display-image.php
Created March 12, 2018 16:09
Serve a random image (JPG) from a specific directory which contains the images.
<?php
// Scan the images directory, remove the folder indicators and reset the index.
$files = array_values(array_diff(scandir('./images'), array('.', '..')));
// Get a random file from the array.
$int = rand(0, (count($files) - 1));
$file = $files[$int];
// Serve the file as JPG content.
@jhammann
jhammann / instagram-scraper.php
Created March 8, 2018 12:36
PHP script to get the 12 latests posts from any public Instagram user.
<?php
header("Content-type: text/json");
header("Content-type: application/json");
// Add the username as a parameter to the URL: /?u=username
$username = $_GET['u'];
$url = 'https://www.instagram.com/' . $username;
$ch = curl_init($url);
@jhammann
jhammann / status-detect.php
Last active March 8, 2018 12:37
Detect the status of any webpage by sending an encoded URL as a query string. This returns a code as JSON.
<?php
header('Content-type: text/json');
header('Content-type: application/json');
$url = urldecode($_GET['url']);
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_NOBODY, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
@jhammann
jhammann / .bash_profile
Created January 12, 2018 15:47
Bash profile snippets
# Git branch in prompt.
parse_git_branch() {
git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/ (\1)/'
}
source /usr/local/git/contrib/completion/git-prompt.sh
export GIT_PS1_SHOWDIRTYSTATE=1
PS1="\[\e[30;46m\] \u \[\e[0m\]\[\e[30;42m\] \W \[\e[0m\]\[\e[37;45m\]\$(__git_ps1 ' ⑂ %s ')\[\e[0m\] $ "
@jhammann
jhammann / geocode_cells.js
Created October 24, 2016 08:12
Google Spreadsheet script for finding lat&lng and/or provinces (NL)
// Function to find the latitude and longitude of a location.
function geocodeSelectedCells() {
var sheet = SpreadsheetApp.getActiveSheet();
var cells = sheet.getActiveRange();
// Must have selected 4 columns (Street, City, Lat and Lng).
// Lat and Lng may ofcourse be empty (but you have to select them anyway).
// Must have selected at least 1 row.
if (cells.getNumColumns() != 4) {