Skip to content

Instantly share code, notes, and snippets.

View kasparsb's full-sized avatar
Checking

Kaspars kasparsb

Checking
View GitHub Profile
@kasparsb
kasparsb / createUniqueModel.php
Created December 3, 2020 15:00
Create Laravel Eloquent Model with unique field. Unique value is generated random string. Uniqueness is handled by mysql unique index
<?php namespace App\Helpers;
use Str;
use Exception;
function createUniqueModel($modelClass, $fieldName='hash', $data=[], $length=48, $tries=0) {
try {
$model = $modelClass::create(
array_merge(
$data,
@kasparsb
kasparsb / index.html
Created July 5, 2018 12:02
Javascript for dynamic script and css loading with cache buster
<script>
(function(d){
var s = d.createElement('link');
d.getElementsByTagName('head')[0].appendChild(s);
s.setAttribute('type', 'text/css');
s.setAttribute('rel', 'stylesheet');
s.setAttribute('href', 'app.css?v='+(new Date()).getTime());
var s = d.createElement('script');
# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).
source /etc/network/interfaces.d/*
# The loopback network interface
auto lo
iface lo inet loopback
# The primary network interface
<?php
/**
* Plugin Name: Tavs plugins
*/
class Tavs_Plugins {
public static $ins;
/**
* Veidojam singletonu
@kasparsb
kasparsb / gist:8258394
Created January 4, 2014 18:11
Initial HTML markup
<!DOCTYPE html>
<html lang="lv-LV">
<head>
<meta charset="UTF-8" />
</head>
<body>
</body>
</html>
@kasparsb
kasparsb / gist:7742958
Created December 2, 2013 00:34
Small backtrace snippet
foreach ( debug_backtrace() as $d )
echo $d['function']."<br />\n";
$data = DB::table( 'wp_usermeta' )
->join('wp_users', 'wp_users.ID', '=', 'wp_usermeta.user_id')
->where('wp_usermeta.meta_key', '=', 'wp_user_level')
->where('wp_usermeta.meta_value', '>', '0')
->orderBy('wp_users.display_name', 'asc')
->select('wp_users.ID as id', 'wp_users.display_name as name' )
->get();