Skip to content

Instantly share code, notes, and snippets.

@fidanov
fidanov / cloudflare_worker.js
Created May 8, 2019 09:27
Resizing images on demand in Cloudflare Workers
/******/ (function(modules) { // webpackBootstrap
/******/ // The module cache
/******/ var installedModules = {};
/******/
/******/ // The require function
/******/ function __webpack_require__(moduleId) {
/******/
/******/ // Check if module is in cache
/******/ if(installedModules[moduleId]) {
/******/ return installedModules[moduleId].exports;
@fidanov
fidanov / app.js
Created August 25, 2014 13:39
Basis express web app.js file.
var express = require('express')
, app = express()
app.engine('jade', require('jade').__express)
app.set('view engine', 'jade')
app.use(express.static(__dirname + '/public'))
app.use(require('./controllers'))
app.listen(3000, function() {
package com.example.package.name;
import java.io.IOException;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.URL;
public class Server {
public static class Result {
public int code;
#import "Utilities.h"
@implementation Utilities
+ (CGSize)text:(NSString *)text sizeWithFont:(UIFont *)font constrainedToSize:(CGSize)size {
if(IOS_NEWER_OR_EQUAL_TO_7) {
CGRect frame = [text boundingRectWithSize: size
options: (NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingUsesFontLeading)
attributes: @{NSFontAttributeName: font}
context:nil];
@fidanov
fidanov / Util.java
Created July 4, 2012 11:26
Android: DIP 2 PX programmatically. Works on any device with any density. Useful when settings width and height in code.
import android.content.Context;
import android.util.TypedValue;
public class Util {
public static int dp(Context context, int size) {
return (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP,
size,
context.getResources().getDisplayMetrics());
}
}
@fidanov
fidanov / Util.java
Created July 2, 2012 08:20
Transform any string to MD5 hash and then to HEX representation. Useful for file names.
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
public class Util {
private static char[] hex = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'};
/**
* Transform any string to MD5 hash and then to HEX representation.
* Very useful for using strings as file names, like when the string
* is a url or another arbitrary string.