Skip to content

Instantly share code, notes, and snippets.

View gintsmurans's full-sized avatar
👏
javascript

Gints Murāns gintsmurans

👏
javascript
View GitHub Profile
@gintsmurans
gintsmurans / error_handler_helper.php
Created September 26, 2012 19:55
Turn php errors into exceptions; Codeigniter's implementation, but can be adapted for every other project.
<?php
# Error handler
function custom_error_handler($errno, $errstr, $errfile, $errline)
{
if (AppSettings::$env == 'dev')
{
throw new ErrorException($errstr, 0, $errno, $errfile, $errline);
}
else
@gintsmurans
gintsmurans / NSArray+RemoveNulls.h
Last active December 11, 2017 09:00
Recursively remove nulls from NSArray and NSDictionary
@interface NSMutableArray (Custom)
- (NSMutableArray *)replaceNullsWithObject:(id)object;
@end
@interface NSMutableDictionary (Custom)
- (NSMutableDictionary *)replaceNullsWithObject:(id)object;
@end
@gintsmurans
gintsmurans / xcode-build-number.sh
Created March 27, 2013 06:57
Bash script for XCode build number automatic increment
#!/bin/bash
bN=$(/usr/libexec/PlistBuddy -c "Print CFBundleVersion" "$INFOPLIST_FILE")
bN=$(echo $bN + 1 | bc)
bN=${bN/\.*}
/usr/libexec/PlistBuddy -c "Set :CFBundleVersion $bN" "$INFOPLIST_FILE"
@gintsmurans
gintsmurans / PEShapeCache.h
Created March 21, 2014 04:05
Cocos2d v3 Physics Editor shape loader
//
// PEShapeCache.h
//
// Put together form the sources all over the internet by Gints Murans.
// No guarantees, of course.
//
/*
This class is used to load physics shapes from a plist created by the
@gintsmurans
gintsmurans / GameCCPhysicsNode.h
Created March 22, 2014 08:04
Pause physics only in cocos2d v3
//
// GameCCPhysicsNode.h
// RollingCandy
//
// Created by Gints Murans on 21/03/14.
// Copyright (c) 2014 Early Bird. All rights reserved.
//
#import "CCPhysicsNode.h"
@gintsmurans
gintsmurans / telegram.py
Last active June 25, 2016 19:30
Telegram (tg) + python cli
#!/usr/bin/env python3
import argparse
import subprocess
import time
import select
PATH_TO_TELEGRAM = '/root/tg/telegram'
@gintsmurans
gintsmurans / session_helpers.php
Created November 5, 2015 11:42
Session expire and destroy other sessions
<?php
const SESSION_EXPIRATION_TIME = 100; // Seconds
function session_expire()
{
if (empty($_SESSION['last_visit'])) {
$_SESSION['last_visit'] = time();
}
if ($_SESSION['last_visit'] + SESSION_EXPIRATION_TIME < time()) {
@gintsmurans
gintsmurans / Functions.php
Last active February 6, 2016 11:02
Various useful php functions
<?php
/**
* Returns fixed floating number with precision of $precision. Replaces "," to "." and " " to "".
*
* @param $input mixed
* @param $precision int
* @return float
*/
function fixFloat($input, $precision = -1)
#!/usr/bin/env python3
# Little library for email and sms (using SMSEagle - http://www.smseagle.eu/) notifications.
# Can be used as a command line or library.
# For this to work please set SMTP and SMSEAGLE parameters
import argparse
import smtplib
import json
from email.mime.text import MIMEText
CREATE OR REPLACE FUNCTION jsonb_array_search(json_arr jsonb, col TEXT, search_for TEXT) RETURNS boolean
LANGUAGE plpgsql IMMUTABLE AS $$
DECLARE
rec jsonb;
len int;
ret boolean = false;
BEGIN
-- If json_arr is not an array, return false
BEGIN
len := jsonb_array_length(json_arr);