Skip to content

Instantly share code, notes, and snippets.

View comm1x's full-sized avatar

Pavel Shorokhov comm1x

View GitHub Profile
@bhrott
bhrott / FuckingSubstringSwift3.md
Last active December 30, 2018 00:34
Fucking substring Swift 3

1 - Create a extensions for String with a new, wonderfull, superpower method called crop:

extension String {
    func crop(from: Int, length: Int) -> String! {
        let startIndex = self.index(self.startIndex, offsetBy: from)
        
        var result = self.substring(from: startIndex)
        
        let endIndex = result.index(result.startIndex, offsetBy: length)
 result = result.substring(to: endIndex)
@bulwinkel
bulwinkel / mapToBundle.kt
Created January 7, 2017 13:35
Partial implementation of converting a `Map<String, V>` to a Bundle.
package com.bulwinkel.android
import android.os.Bundle
import android.os.IBinder
import android.os.Parcelable
import java.io.Serializable
fun <V> Map<String, V>.toBundle(bundle: Bundle = Bundle()): Bundle = bundle.apply {
forEach {
val k = it.key
@Bhavdip
Bhavdip / sketch-never-ending.md
Created October 6, 2016 15:53
Modify Sketch to never ending trial

###Sketch trial non stop

Open hosts files:

$ open /private/etc/hosts

Edit the file adding:

127.0.0.1 backend.bohemiancoding.com

127.0.0.1 bohemiancoding.sketch.analytics.s3-website-us-east-1.amazonaws.com

@lukaspili
lukaspili / ScrollableViewController.swift
Last active March 17, 2023 12:35
Scroll view snap kit
import UIKit
import SnapKit
class ScrollableViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
view.backgroundColor = UIColor.whiteColor()
let scrollView = UIScrollView()
@BR0kEN-
BR0kEN- / string_functions.sh
Created June 8, 2015 11:25
Bash implementation of strpos and substr functions from PHP library
#!/usr/bin/env bash
# @param string $1
# Input string.
# @param int $2
# Cut an amount of characters from left side of string.
# @param int [$3]
# Leave an amount of characters in the truncated string.
substr()
{
@GaryJones
GaryJones / RedirectsCept.php
Last active May 20, 2019 15:21
Codeception 301 Redirection Tests
<?php
$I = new RedirectsTester($scenario);
$I->wantTo('check 301 redirects are working');
// First, test /login/ page gets rewritten to https://
$I->seePermanentRedirectToHttpsFor('login/');
$I->seePermanentRedirectToHttpsFor('login/?redirect_to=foo');
@cyrilmottier
cyrilmottier / ResourcesAdditions.java
Last active January 12, 2024 17:55
Lightweight key-value pairs resources for Android applications.
package com.cyrilmottier.android.resourcesadditions;
import android.content.res.Resources;
import android.content.res.XmlResourceParser;
import android.os.Bundle;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
/**
* @author Cyril Mottier
@eusonlito
eusonlito / foldersize.php
Last active July 25, 2023 12:50
PHP function to get the folder size including subfolders
<?php
function folderSize ($dir)
{
$size = 0;
foreach (glob(rtrim($dir, '/').'/*', GLOB_NOSORT) as $each) {
$size += is_file($each) ? filesize($each) : folderSize($each);
}
@nikic
nikic / objects_arrays.md
Last active April 12, 2024 17:05
Post explaining why objects often use less memory than arrays (in PHP)

Why objects (usually) use less memory than arrays in PHP

This is just a small post in response to [this tweet][tweet] by Julien Pauli (who by the way is the release manager for PHP 5.5). In the tweet he claims that objects use more memory than arrays in PHP. Even though it can be like that, it's not true in most cases. (Note: This only applies to PHP 5.4 or newer.)

The reason why it's easy to assume that objects are larger than arrays is because objects can be seen as an array of properties and a bit of additional information (like the class it belongs to). And as array + additional info > array it obviously follows that objects are larger. The thing is that in most cases PHP can optimize the array part of it away. So how does that work?

The key here is that objects usually have a predefined set of keys, whereas arrays don't:

@handerson
handerson / mysqlfix.sh
Created March 27, 2012 16:52 — forked from davejlong/mysql client
How to setup the MySQL client and MySQLDump client on Mac OS x from MySQL Workbench
#MySQL Client
ln -s /Applications/MySQLWorkbench.app/Contents/Resources/mysql /usr/bin/mysql
#MySQL Dump
ln -s /Applications/MySQLWorkbench.app/Contents/Resources/mysqldump /usr/bin/mysqldump
#How to fix the "Library not loaded: libmysqlclient.18.dylib (LoadError)" error
sudo ln -s /usr/local/mysql/lib/libmysqlclient.18.dylib /usr/lib/libmysqlclient.18.dylib