Skip to content

Instantly share code, notes, and snippets.

View mauris's full-sized avatar
🟢
Get things done

Sam Y mauris

🟢
Get things done
View GitHub Profile
@mauris
mauris / gist:3629548
Created September 5, 2012 02:49
Generating Random even or odd number using mt_rand and bitshifting
<?php
$randomValue = mt_rand();
$even = $randomValue & ~1;
$odd = $randomValue | 1;
// magical unicorn isn't it?
@mauris
mauris / queue-ensure.php
Created April 28, 2014 15:44
Laravel Artisan Queue Ensurer - Set a cron job to run this file periodically to ensure that Laravel's queue is processing all the time. If the queue listener stopped, restart it!
<?php
function runCommand ()
{
$command = 'php artisan queue:listen > /dev/null & echo $!';
$number = exec($command);
file_put_contents(__DIR__ . '/queue.pid', $number);
}
if (file_exists(__DIR__ . '/queue.pid')) {
@mauris
mauris / paynow.js
Created July 14, 2022 06:54 — forked from chengkiang/paynow.js
SG PayNow QR Code Generator Sample
String.prototype.padLeft = function (n, str) {
if (n < String(this).length) {
return this.toString();
}
else {
return Array(n - String(this).length + 1).join(str || '0') + this;
}
}
function crc16(s) {
@mauris
mauris / export.js
Last active August 29, 2018 15:17
Github Repository Labels Import / Export - Aug 2018
// Thanks to MoOx and martindafonte over at
// https://gist.github.com/MoOx/93c2853fee760f42d97f
var labels = [];
[].slice.call(document.querySelectorAll(".label-link"))
.forEach(function(element) {
labels.push({
name: element.textContent.trim(),
description: element.getAttribute("aria-label"),
// using style.backgroundColor might returns "rgb(...)"
@mauris
mauris / git-deletealltags.bat
Created April 28, 2013 03:05
Script to delete all git tags remotely and locally on Windows Command Batchfile. Based on https://gist.github.com/matthewmccullough/898798
@echo off
for /F %%G IN ('git tag') DO git push origin :%%G && git tag -d %%G
@mauris
mauris / print.sh
Last active January 14, 2018 23:11
#!/bin/sh
# Printing PDF files from your command prompt.
# 1. Create a "print" folder in your home directory.
# 2. Put this "print.sh" in the "print" folder.
# 3. Run "chmod +x print.sh" to make me executable
# 4. For each time you want to print PDF files:
# i) Place a copy of the PDF files in the "print" folder
# ii) run "./print.sh"
@mauris
mauris / NricUtility.php
Created September 8, 2013 13:41
A NRIC utility class implemented in PHP. For validating NRIC numbers or generating random NRIC numbers.
<?php
namespace Mauris\Utility;
class NricUtility
{
public static function validate($nric)
{
$nric = strtoupper($nric);
if (strlen($nric) == 9) {
$hash = self::checksum(substr($nric, 0, 8));
@mauris
mauris / fib.js
Last active November 28, 2017 19:22
Fibonacci Dynamic Programming
// The mathematical definition (i.e. simple recursion):
function fib(n) {
if (n < 1) { // base case 1
return 0;
}
if (n < 3) { // base case 2
return 1;
}
// recursion steps
@mauris
mauris / gist:5558889
Created May 11, 2013 04:27
Sample BitBucket payload for hook services
{
"canon_url": "https:\/\/bitbucket.org",
"commits": [
{
"author": "mauris",
"branch": "master",
"files": [
{
"file": "test",
"type": "added"
export RUNFILE=BabyNames; javac $RUNFILE.java; for file in *.in; do java $RUNFILE < $file | diff ${file%.*}.out -; done