Skip to content

Instantly share code, notes, and snippets.

View slav123's full-sized avatar

Slawomir Jasinski slav123

View GitHub Profile
// Author - Santosh Rajan
import Foundation
let string = "{\"name\": \"John\", \"age\": 35, \"children\": [\"Jack\", \"Jill\"]}"
func JSONParseDictionary(jsonString: String) -> [String: AnyObject] {
if let data = jsonString.dataUsingEncoding(NSUTF8StringEncoding) {
if let dictionary = NSJSONSerialization.JSONObjectWithData(data, options: NSJSONReadingOptions(0), error: nil) as? [String: AnyObject] {
return dictionary
<?xml version="1.0" encoding="UTF-8"?>
<phpunit
colors="true"
stopOnFailure="false"
backupGlobals="false"
backupStaticAttributes="false"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
@slav123
slav123 / CITest.php
Created March 27, 2015 05:51
Unit testing sample with CI 3
<?php
class CITest extends PHPUnit_Framework_TestCase
{
private $CI;
public function setUp()
{
// Load CI instance normally
$this->CI = &get_instance();
}
@slav123
slav123 / post.php
Last active September 17, 2021 10:30
PHP POST request with file_get_contents
<?php
$data = [];
// www-form-urlencoded
$opts = array('http' => array('method' => 'POST',
'header' => 'Content-Type: application/x-www-form-urlencoded',
'content' => http_build_query($data)
));
// json
@slav123
slav123 / rw.swift
Created April 20, 2015 02:44
read write from files in swift
let fileMgr = NSFileManager.defaultManager() func saveToFile(str: String, file: String) { var path = NSHomeDirectory().stringByAppendingPathComponent ("Documents").stringByAppendingPathComponent(file) Note Each app can write only to certain a certain folder inside the application home (for example, the Documents folder). The most common error is probably trying to create a file in the wrong place. var data = str.dataUsingEncoding(NSUTF8StringEncoding) var ok = fileMgr.createFileAtPath(path, contents: data, attributes: nil) } func retrieveFromFile(file: String) -> String? { var path = NSHomeDirectory().stringByAppendingPathComponent ("Documents").stringByAppendingPathComponent(file) if let data = fileMgr.contentsAtPath(path) { return NSString(data:data, encoding: NSUTF8StringEncoding) } return nil } func deleteFile(file: String) { var path = NSHomeDirectory().stringByAppendingPathComponent ("Documents").stringByAppendingPathComponent(file) var ok = fileMgr.remo
@slav123
slav123 / dismiss
Created April 20, 2015 02:47
dismiss for modal swift
self.dismissViewControllerAnimated(true, completion: {});//This is intended to dismiss the Info sceen.
@slav123
slav123 / dismiss
Created April 20, 2015 02:48
dismiss view swift
navigationController?.popViewControllerAnimated(true)
@slav123
slav123 / new_gist_file_0
Created April 22, 2015 09:09
repo update
yum --disablerepo="*" --enablerepo="geekery" list available
yum --disablerepo="*" --enablerepo="geekery" update
@slav123
slav123 / get_vips.sh
Last active January 15, 2019 13:06
vips AMI sh
#!/bin/sh
vips_version_minimum=8.2.2
vips_version_latest_major_minor=8.2
vips_version_latest_patch=2
install_libvips_from_source() {
echo "Compiling libvips $vips_version_latest_major_minor.$vips_version_latest_patch from source"
curl -O http://www.vips.ecs.soton.ac.uk/supported/$vips_version_latest_major_minor/vips-$vips_version_latest_major_minor.$vips_version_latest_patch.tar.gz
tar zvxf vips-$vips_version_latest_major_minor.$vips_version_latest_patch.tar.gz
@slav123
slav123 / multiline.php
Created May 7, 2015 02:37
long code in PHP
<?php
$var = "some text";
$text = <<<EOT
Place your text between the EOT. It's
the delimiter that ends the text
of your multiline string.
$var
EOT;
// The difference between Heredoc and Nowdoc is, that php code embedded in an heredoc gets executed, while php code in Nowdoc will be printed out as is.