Skip to content

Instantly share code, notes, and snippets.

View olssonm's full-sized avatar
🖥️
Working on some cool stuff

Marcus Olsson olssonm

🖥️
Working on some cool stuff
View GitHub Profile
@olssonm
olssonm / encodeEmail
Created March 18, 2013 10:44
Spam is shit. If you entity-encode your e-email adress those annoying little robots will have a more difficult time getting to it, and it stills allow you to show it as plain text. This an encoder for wordpress (just put it in your functions.php). Example: example@example.com would become: example@e&#…
add_shortcode('email', 'encodeEmail');
function encodeEmail($attr) {
extract(shortcode_atts(array(
'adress' => 'nothing',
'text' => 'nothing',
), $attr));
function encodeToEntity($str) {
$str = mb_convert_encoding($str , 'UTF-32', 'UTF-8');
$t = unpack("N*", $str);
@olssonm
olssonm / route caching laravel php
Created September 2, 2014 07:32
Laravel 4.2 route caching
<?php
/**
* For caching routes
*/
Route::filter('cache', function($route, $request, $response = null) {
$cacheTagKey = Config::get('values.cacheKeys.tags_routes');
// Do not cache if the devcookie is set
if(Util::testDevCookie() == false) {
@olssonm
olssonm / python-namnapi-json-parse
Created May 5, 2015 15:23
Parse JSON from NamnAPI v2 with Python
from urllib import urlopen
import json
data = urlopen('http://api.namnapi.se/v2/names.json?limit=10').read()
data = json.loads(data)
for name in data['names']:
print name['firstname']
print name['surname']
print name['gender']
@olssonm
olssonm / attr.php
Created February 11, 2016 14:34
Simple all-fetching method for a base model in Laravel 5+
/**
* Retrieve an attribute value, or a default value, depending on if attribute is set
* @param string $attribute name of attribute
* @param mixed $default the default value
* @return mixed the attribute
*/
public function attr($attribute, $default = null)
{
if (isset($this->attributes[$attribute]) && $this->attributes[$attribute] != null) {
return $this->attributes[$attribute];
@olssonm
olssonm / BasicAuthFilter.php
Last active September 14, 2016 12:55
Basic authentication for Laravel 4, based on https://github.com/olssonm/l5-very-basic-auth
<?php
Route::filter('auth.very_basic', function($request, $response)
{
// Load configuration
$veryBasicAuthUser = 'admin';
$veryBasicAuthPass = 'admin';
$veryBasicAuthEnvs = array('dev');
$veryBasicAuthMsg = 'Access denied';
// Check if middleware is in use in current environment
@olssonm
olssonm / fat32
Created November 19, 2016 09:54
Formatting USB/SD-cards etc. to FAT32 in macOS
// Find the correct disk with diskutil
$ diskutil list
// Erase and format drive where "NAME" is the desired name (in capital letters) and "/dev/disk" is the target disk
$ sudo diskutil eraseDisk FAT32 NAME MBRFormat /dev/disk
@olssonm
olssonm / definer.sh
Created June 16, 2017 09:14
Remove definer constraints on a a MySQL-dump in macOS
sed -i '' 's/DEFINER=`[^`][^`]*`@`[^`][^`]*`//g' filename.sql
@olssonm
olssonm / .bash_profile
Created June 22, 2017 07:18
Quick shortcut to copy your ssh key
function copykey() {
pbcopy < ~/.ssh/id_rsa.pub
echo "Key copied!"
}
@olssonm
olssonm / homestead56.yaml
Created July 6, 2017 13:13
Laravel Homestead
---
ip: "192.168.10.20"
version: 0.3.3
memory: 2048
cpus: 1
hostname: homestead56
name: homestead56
provider: virtualbox
authorize: ~/.ssh/id_rsa.pub
keys:

Keybase proof

I hereby claim:

  • I am olssonm on github.
  • I am olssonm (https://keybase.io/olssonm) on keybase.
  • I have a public key ASCzC811GvJdvWmN0-mAQKbO6LG3DHz0paOzwnfef4rVfwo

To claim this, I am signing this object: