Skip to content

Instantly share code, notes, and snippets.

View nazywamsiepawel's full-sized avatar
:bowtie:
hummus is life

pawel.io nazywamsiepawel

:bowtie:
hummus is life
View GitHub Profile
@nazywamsiepawel
nazywamsiepawel / asdf.c
Created December 6, 2012 14:34
node.js simple
var http = require('http');
http.createServer(function (req, res) {
res.writeHead(200, {'Content-Type': 'text/plain'});
res.end('Hello World\n');
}).listen(3000, '127.0.0.1');
console.log('Server running at http://127.0.0.1:3000/');
@nazywamsiepawel
nazywamsiepawel / asdf.c
Created December 6, 2012 14:34
node.js simple
var http = require('http');
http.createServer(function (req, res) {
res.writeHead(200, {'Content-Type': 'text/plain'});
res.end('Hello World\n');
}).listen(3000, '127.0.0.1');
console.log('Server running at http://127.0.0.1:3000/');
function wordWrap(text){
var words = text.split(' ');
var charWidth = 6; // and then suddenly a charWidth appeared.
var horizotalLimit = 200;
var lines = [];
var currentLine = 0;
lines.push({line : '', text_length : 0});
var i = 0;
@nazywamsiepawel
nazywamsiepawel / gist:6615365
Created September 18, 2013 20:42
merge sort using stl queues
#include <iostream>
#include <queue>
using namespace std;
void merge(int s[], int low, int middle, int high){
int i;
queue<int> buffer1, buffer2;
for(i=low; i<=middle; i++) buffer1.push(s[i]);
@nazywamsiepawel
nazywamsiepawel / gist:8937544
Created February 11, 2014 15:50
Recursively sort object keys
var _ = require('underscore');
function sortObject(obj){
var oNew = {};
if(typeof obj === 'object'){
var aKeys = _.keys(obj);
aKeys.sort();
_.each(aKeys, function(sKey, oVal){
oNew[sKey] = sortObject(obj[sKey]);
});
/* Swift notes */
import Cocoa
/* Use let to make a contant and var to make a variable, implicitly infer the type */
var cheesyVariable = 100
let cheesyConstant = 666
let implicitDouble = 70.0
Graph.prototype.forces = function(){
for(var i=0; i<this.nodesList.length; i++){
netForceX = 0;
netForceY = 0;
var dsq;
var a = this.nodesList[i];
/*calculate repulsion*/
for(var j=0; j<this.nodesList.length; j++){
var b = this.nodesList[j];
@nazywamsiepawel
nazywamsiepawel / keychain
Created October 16, 2014 09:10
Keychain troubleshooting
import UIKit
import Security
let serviceIdentifier = "com.Test.KeychainTest"
let kSecClassValue = kSecClass as NSString
let kSecAttrAccountValue = kSecAttrAccount as NSString
let kSecValueDataValue = kSecValueData as NSString
let kSecClassGenericPasswordValue = kSecClassGenericPassword as NSString
let kSecAttrServiceValue = kSecAttrService as NSString
@nazywamsiepawel
nazywamsiepawel / UINavigationBarWithSubtitle.swift
Last active July 20, 2023 11:58
UINavigationBar with subtitle / swift
func setTitle(title:String, subtitle:String) -> UIView {
let titleLabel = UILabel(frame: CGRect(x:0, y:-5, width:0, height:0))
titleLabel.backgroundColor = UIColor.clear
titleLabel.textColor = UIColor.gray
titleLabel.font = UIFont.boldSystemFont(ofSize: 17)
titleLabel.text = title
titleLabel.sizeToFit()
@nazywamsiepawel
nazywamsiepawel / NSURL+params.swift
Created September 3, 2015 12:18
Extract query parameters from NSURL
extension NSURL {
func queryParams() -> Dictionary<String, String> {
var params = Dictionary<String, String>()
if let queryParams = self.query?.componentsSeparatedByString("&") {
for param in queryParams {
var parts = param.componentsSeparatedByString("=")
params[parts[0]] = parts[1]
}
}