Skip to content

Instantly share code, notes, and snippets.

@martisj
martisj / matrix.py
Created Oct 28, 2020
Matrixify your life
View matrix.py
class Matrix:
def __init__(self, matrix_string):
self.matrix = matrix_string.split("\n")
def row(self, index):
row = self.matrix[index - 1]
row_list = row.split()
final_list = list(map(int, row_list))
return final_list
@martisj
martisj / app.js
Last active Feb 28, 2017
HTTPS redirect express.js node kind of specifically for Heroku
View app.js
const express = require('express');
const app = express();
app.use((req, res, next) => {
if (req.headers['x-forwarded-proto'] !== 'https' && process.env.NODE_ENV === 'production') {
res.redirect(`https://${req.hostname}${req.url}`);
} else {
next();
}
});
View osx_php_homebrew.setup.md

install php

with mysql pgsql intl support

$ brew install php --with-apache --with-mysql --with-pgsql --with-intl

set php timezone in php ini

date.timezone = Europe/Vienna
View gist:5507050
<?php
$action = (isset($_POST['__action'])) ? $_POST['__action'] : null; // is the action we have to take
$err = array(); // empty array to hold any processing errors
if($action){ // there is an action
if($action == 'email'){
// we must process the email form
require_once('send.php'); // require the file needed to process email form
View jskatta.js
var $element_store;
$camp_photos.on('click', '.top_level_image_link', function() {
var $this = $(this);
var $photo_albums = $('#photo_albums');
$element_store = $photo_albums;
var $photo_album_to_load = $('#photo_album-' + $this.data('album-id'));
// replace_content_and_make_slides(new_html, container);
$camp_photos.animate({opacity: 0}, 'fast', function() {
View colors.fish
if $COLORTERM gnome-* and $TERM = xterm and infocmp gnome-256color >/dev/null 2>&1
set -x TERM=gnome-256color
else if infocmp xterm-256color >/dev/null 2>&1
set -x TERM=xterm-256color
end
if [[tput setaf 1]] &> /dev/null
tput sgr0
if [[ tput colors -ge 256 ]] 2>/dev/null
set -x MAGENTA (tput setaf 9)
View hcard test
<article class="vcard">
<a href="mailto:basket@basketskolen.no" class="email">basket@basketskolen.no</a>
På telefon etter klokken 16:00 på hverdager:
<div class="vcard">
<span class="fn">Dag</span>:<span class="tel">+47 92 89 89 81</span>
</div>
<div class="vcard">
<span class="fn">Jan</span>:<span class="tel">+47 91 85 85 95</span>
</div>
</article>
View home.php
<?php
/**
* The main template file.
*
* This is the most generic template file in a WordPress theme
* and one of the two required files for a theme (the other being style.css).
* It is used to display a page when nothing more specific matches a query.
* E.g., it puts together the home page when no home.php file exists.
* Learn more: http://codex.wordpress.org/Template_Hierarchy
*
@martisj
martisj / htaccess
Last active Dec 11, 2015
doesnt rewrite to correct url
View htaccess
# Use PHP5 Single php.ini as default
AddHandler application/x-httpd-php5s .php
RewriteEngine On
#For martinsjastad.com and frontsideinteractive.com
# automatically redirect user from www.martinsjastad.com to martinsjastad.com
# automatically redirect user from www.frontsideinteractive.com to frontsideinteractive.com
RewriteCond %{HTTP_HOST} =www.martinsjastad.com [NC]
RewriteRule (.*) http://martinsjastad.com/$1 [R=301,L]
@martisj
martisj / if_elseif_fail.php
Created Jan 18, 2013
class to 3rd and higher than 7th elem
View if_elseif_fail.php
$class = '';
if (($i + 1) % 3 == 0)
{
$class .= 'nth-child-3n';
}
elseif (($i + 1) > 6)
{
$class .= ' nth-child-nplus7';
}