Skip to content

Instantly share code, notes, and snippets.

View nacho4d's full-sized avatar

Guillermo Ignacio Enriquez Gutierrez nacho4d

View GitHub Profile
@nacho4d
nacho4d / exampleJavaxJson.java
Created August 3, 2016 13:47
javax.json is too much hassle
JsonObject json = Json.createObjectBuilder()
.add("keyString", "string")
.add("keyBoolean", true)
.add("keyArraySimple", Json.createArrayBuilder()
.add(1)
.add(11)
.add(111).build())
.add("keyArrayObject", Json.createArrayBuilder()
.add(Json.createObjectBuilder()
.add("lang", "ja")
@nacho4d
nacho4d / JsonUtils.java
Last active May 19, 2021 15:16
Because javax.json.Json is just too much hassle
package com.company.project.util;
import java.io.StringReader;
import java.io.StringWriter;
import javax.json.Json;
import javax.json.JsonObject;
import javax.json.JsonReader;
import javax.json.JsonWriter;
@nacho4d
nacho4d / BasicAuthenticationFilter.java
Last active July 12, 2018 18:15 — forked from neolitec/BasicAuthenticationFilter.java
HTTP Basic authentication Java filter (Without external dependencies)
package com.company.project.filter;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
@nacho4d
nacho4d / myproject_pom.xml
Last active February 17, 2017 16:21
myproject/pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<!-- THIS PRODUCT CONTAINS RESTRICTED MATERIALS OF IBM 5724-H88, 5724-J08,
5724-I63, 5655-W65, COPYRIGHT International Business Machines Corp., 2014
All Rights Reserved * Licensed Materials - Property of IBM US Government
Users Restricted Rights - Use, duplication or disclosure restricted by GSA
ADP Schedule Contract with IBM Corp. -->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<licenses>
@nacho4d
nacho4d / build-fat.sh
Created October 8, 2015 08:22
Make universal framework at build time to pass github binary size restrictions
cd "${PROJECT_DIR}/MyProject/lib/"
libs=( IBMMobileFirstPlatformFoundation sqlcipher )
archs=( armv7 armv7s i386 x86_64 arm64 )
# create bunch of thin files.
function lipo_extract() {
lib=${1}
pushd "${lib}.framework" > /dev/null
for arch in "${archs[@]}"; do
@nacho4d
nacho4d / worklight.log
Created August 27, 2015 07:31
long stack trace
[8/27/15 15:53:39:235 JST] 0000008b ication.internal.jaas.modules.UsernameAndPasswordLoginModule A CWWKS1100A: Authentication did not succeed for user ID oLs3jn4fNG. An invalid user ID or password was specified.
[8/27/15 15:53:39:350 JST] 000000b0 SystemErr R java.util.zip.ZipException: zip file is empty
[8/27/15 15:53:39:350 JST] 000000b0 SystemErr R at java.util.zip.ZipFile.open(Native Method)
[8/27/15 15:53:39:351 JST] 000000b0 SystemErr R at java.util.zip.ZipFile.<init>(ZipFile.java:220)
[8/27/15 15:53:39:351 JST] 000000b0 SystemErr R at java.util.zip.ZipFile.<init>(ZipFile.java:150)
[8/27/15 15:53:39:351 JST] 000000b0 SystemErr R at java.util.jar.JarFile.<init>(JarFile.java:166)
[8/27/15 15:53:39:351 JST] 000000b0 SystemErr
// There is a bug in WebKit
// Local files cannot be read unless they are in the tmp/www/ directory!
// Example: read "file.pdf" into WKWebView
var fileManager = NSFileManager.defaultManager()
var srcPath = NSBundle.mainBundle().pathForResource("file", ofType: "pdf")
var tmpPath = NSTemporaryDirectory().stringByAppendingPathComponent("www")
// TODO: handler errors correctly
fileManager.createDirectoryAtPath(tmpPath, withIntermediateDirectories: true, attributes: nil, error: nil)
var dstPath = tmpPath.stringByAppendingPathComponent("file.pdf")
$ swiftc -emit-ir /Users/nacho4d/Desktop/function2/function2/main.swift -sdk /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.10.sdk
; ModuleID = '-'
target datalayout = "e-m:o-i64:64-f80:128-n8:16:32:64-S128"
target triple = "x86_64-apple-darwin14.0.0"
%0 = type opaque
%1 = type opaque
%Si = type <{ i64 }>
%CSo8NSObject = type opaque
%swift.type = type { i64 }
@nacho4d
nacho4d / MajorityElement
Last active August 29, 2015 14:12
Majority element
// https://oj.leetcode.com/problems/majority-element/
// Given an array of size n, find the majority element. The majority element is the element that appears more than ⌊ n/2 ⌋ times.
// You may assume that the array is non-empty and the majority element always exist in the array.
class Solution {
public:
// Hash table
int majorityElement_hashtable(vector<int> &num) {
std::map <int, int> table;
for (int n : num) {
@nacho4d
nacho4d / compile.sh
Created December 16, 2014 07:48
Compile file for C# CodeRunner. It runs even when gmcs gives warnings. (After showing them)
#!/bin/bash -x
# This is a CodeRunner compilation script. Compilation scripts are used to
# compile code before being run using the run command specified in CodeRunner
# preferences. This script should have the following properties:
#
# Launch directory ($PWD): Will be the same as the file being run
#
# Exit status: Should be 0 on success (will cause CodeRunner
# to continue and execute the run command)
#