Skip to content

Instantly share code, notes, and snippets.

View samwize's full-sized avatar
💭
 writing apps i want to use

Junda samwize

💭
 writing apps i want to use
View GitHub Profile
@samwize
samwize / pre-commit
Last active May 9, 2022 07:25 — forked from candostdagdeviren/pre-commit
Git Pre-Commit hook with SwiftLInt
#!/bin/bash
SWIFT_LINT=./Pods/SwiftLint/swiftlint
if [[ -e "${SWIFT_LINT}" ]]; then
# Export files in SCRIPT_INPUT_FILE_$count to lint against later
count=0
while IFS= read -r file_path; do
export SCRIPT_INPUT_FILE_$count="$file_path"
count=$((count + 1))
class MyViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
do {
try fetchedResultsController.performFetch()
} catch {
print("Error")
}
}
@samwize
samwize / DynamicKey.swift
Created September 28, 2017 06:59
A CodingKey that is dynamic -- it can be any string! Encode/decode with a Dictionary of `[String : Any]` in the model.
/**
```
// Encode a model with properties of type [String : Any]
var propertiesContainer = container.nestedContainer(keyedBy: DynamicKey.self, forKey: .properties)
if let properties = properties {
try propertiesContainer.encodeDynamicKeyValues(withDictionary: properties)
}
```
*/
struct DynamicKey: CodingKey {
@samwize
samwize / UIImage+Resize.swift
Created June 1, 2016 06:35
The original code to resize UIImage
extension UIImage {
func resizedImage(newSize:CGSize) -> UIImage {
UIGraphicsBeginImageContextWithOptions(newSize, false, 0.0);
self.drawInRect(CGRectMake(0, 0, newSize.width, newSize.height))
let newImage: UIImage = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext()
return newImage
}
{
"images" : [
{
"size" : "29x29",
"idiom" : "iphone",
"filename" : "app-icon-58.png",
"scale" : "2x"
},
{
"size" : "40x40",
@samwize
samwize / mocha-guide-to-testing.js
Created February 8, 2014 05:53
Explain Mocha's testing framework - describe(), it() and before()/etc hooks
// # Mocha Guide to Testing
// Objective is to explain describe(), it(), and before()/etc hooks
// 1. `describe()` is merely for grouping, which you can nest as deep
// 2. `it()` is a test case
// 3. `before()`, `beforeEach()`, `after()`, `afterEach()` are hooks to run
// before/after first/each it() or describe().
//
// Which means, `before()` is run before first it()/describe()
@samwize
samwize / activity_main.xml
Created October 10, 2013 15:19
Stopwatch layout
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<FrameLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_alignParentTop="true"
@samwize
samwize / MainActivity.java
Last active December 25, 2015 02:39
Add custom font to timerTextView
package com.example.stopwatch;
import android.os.Bundle;
import android.app.Activity;
import android.os.Handler;
import android.view.Menu;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
@samwize
samwize / HoiioSignature.java
Created December 14, 2012 08:25
Compute signature of a http from Hoiio. This is used to authenticate the notification from Hoiio. Match this computed signature with the HTTP header "X-Hoiio-Signature".
public String computeHoiioSignature(byte[] payload, String accessToken) {
MessageDigest md = MessageDigest.getInstance("SHA-256");
md.update(payload);
md.update(accessToken.getBytes("UTF-8"));
byte[] bytes = md.digest();
String mySign = Hex.encodeHexString(bytes);
return mySign;
}
@samwize
samwize / hoiio_signature.php
Created December 14, 2012 08:21
Compute signature of a http from Hoiio. This is used to authenticate the notification from Hoiio. Match this computed signature with the HTTP header "X-Hoiio-Signature".
<?php
function computeHoiioSignature($payload, $accessToken) {
// hash_hmac will return a hex of the digest
$signature =hash_hmac('sha256', $payload, $accessToken);
return $signature;
}
?>