Skip to content

Instantly share code, notes, and snippets.

@evnm
evnm / array-sum-example
Created September 24, 2011 05:36
Java vs Scala array sum example
// Java.
int sum = 0;
for (int i = 0; i < arr.length; i++) {
sum += arr[i];
}
System.out.println(sum);
// Scala (ignoring arr.sum).
println(arr reduceLeft { _ + _ })
@fawkeswei
fawkeswei / AFNetworking_post_json.m
Created September 13, 2012 14:39
How to post json data using AFNetworking
NSURL *url = [NSURL URLWithString:@"http://someurl.com/"];
AFHTTPClient *httpClient = [[AFHTTPClient alloc] initWithBaseURL:url];
// don't forget to set parameterEncoding!
httpClient.parameterEncoding = AFJSONParameterEncoding;
NSDictionary *params = @{@"key" : @"value"};
NSMutableURLRequest *request = [httpClient requestWithMethod:@"POST" path:@"" parameters:params];
AFHTTPRequestOperation *operation = [AFJSONRequestOperation JSONRequestOperationWithRequest:request success:nil failure:nil];
[operation start];
[[UINavigationBar appearance] setTintColor:[UIColor grayColor]];
[[UIBarButtonItem appearance] setBackButtonTitlePositionAdjustment:UIOffsetMake(0, -60) forBarMetrics:UIBarMetricsDefault]; // Takes out title
UIImage *backButtonImage = [UIImage imageNamed:@"BackArrowDark.png"];
if ([UINavigationBar instancesRespondToSelector:@selector(setBackIndicatorImage:)]) {
[[UINavigationBar appearance] setBackIndicatorImage:backButtonImage];
[[UINavigationBar appearance] setBackIndicatorTransitionMaskImage:backButtonImage];
} else {
int imageSize = 21; // REPLACE WITH YOUR IMAGE WIDTH
@cdesch
cdesch / Procfile
Created November 4, 2014 15:27
Dukko unicorn.rb
web: bundle exec unicorn -p $PORT -c ./config/unicorn.rb
@SiddheshShetye
SiddheshShetye / RoundedCornerNetworkImageView.java
Last active January 25, 2017 22:23
NetworkImageView Is a Custom ImageView class.Provides all the functionalities of NetworkImageView from Volley. In addition to those this class provides functionality of rounded edges for the ImageView with gradient effect.This Class is dependent on StreamDrawable from RomainGuy in his Image With Rounded Corners Demo but with little modifications.
/*
* Copyright (C) 2013 Siddhesh S Shetye
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
@hpique
hpique / iOS7-notifications.h
Last active January 29, 2018 14:19
List of all public notifications available in iOS 7.0 (or at least those whose constants are properly named).
// Developer/Library/Frameworks/SenTestingKit.framework/Headers/SenTestCaseRun.h
SENTEST_EXPORT NSString * const SenTestCaseDidStartNotification;
SENTEST_EXPORT NSString * const SenTestCaseDidStopNotification;
SENTEST_EXPORT NSString * const SenTestCaseDidFailNotification;
// Developer/Library/Frameworks/SenTestingKit.framework/Headers/SenTestDistributedNotifier.h
SENTEST_EXPORT NSString * const SenTestNotificationIdentifierKey;
// Developer/Library/Frameworks/SenTestingKit.framework/Headers/SenTestSuiteRun.h
SENTEST_EXPORT NSString * const SenTestSuiteDidStartNotification;
#! /bin/bash
# directory to save backups in, must be rwx by postgres user
BASE_DIR="/var/backups/postgres"
YMD=$(date "+%Y-%m-%d")
DIR="$BASE_DIR/$YMD"
mkdir -p $DIR
cd $DIR
# make database backup
#!/bin/sh
BOOT2DOCKER_CERTS_DIR=/var/lib/boot2docker/certs
CERTS_DIR=/etc/ssl/certs
CAFILE=${CERTS_DIR}/ca-certificates.crt
for cert in $(/bin/ls -1 ${BOOT2DOCKER_CERTS_DIR}); do
SRC_CERT_FILE=${BOOT2DOCKER_CERTS_DIR}/${cert}
CERT_FILE=${CERTS_DIR}/${cert}
HASH_FILE=${CERTS_DIR}/$(/usr/local/bin/openssl x509 -noout -hash -in ${SRC_CERT_FILE} 2>/dev/null)
@youmee
youmee / PluralForm.swift
Last active January 16, 2020 14:20
Swift Russian Plural Form Function
/*
pluralForm(28, forms: ["год", "года", "лет"])
output: "лет"
*/
func pluralForm(number: Int, forms: [String]) -> String {
return number % 10 == 1 && number % 100 != 11 ? forms[0] :
(number % 10 >= 2 && number % 10 <= 4 && (number % 100 < 10 || number % 100 >= 20) ? forms[1] : forms[2])
}
@jchernandez
jchernandez / SimpleRequest.java
Last active August 3, 2020 20:41
Simple Post Request with basic auth, using android Volley library
StringRequest request = new StringRequest(Request.Method.POST, url, new Response.Listener<String>() {
@Override
public void onResponse(String s) {
///handle response from service
}, new ErrorResponse() {
@Override
public void onErrorResponse(VolleyError volleyError) {
//handle error response
}
}) {