Skip to content

Instantly share code, notes, and snippets.

@eienf
eienf / toBinary.swift
Created March 17, 2016 16:23
Binary String from Number types
// toBinary
func toBinary<T: UnsignedIntegerType>(value: T) -> String {
let str = String(value, radix:2)
let size = sizeofValue(value) * 8
let padd = String(count: (size - str.characters.count), repeatedValue: Character("0"))
return padd + str
}
func toBinary<T: _SignedIntegerType>(value: T) -> String {
let size = sizeofValue(value) * 8
let signed: IntMax = value.toIntMax()
<html>
<head>
<script type="text/javascript" src="https://www.google.com/jsapi"></script>
<script type="text/javascript">
google.load("visualization", "1.1", {packages:["geochart"]});
google.setOnLoadCallback(drawRegionsMap);
function drawRegionsMap() {
/* 0…未踏、1…通過、2…接地、3…訪問、4…宿泊、5…居住 */
var data = google.visualization.arrayToDataTable([
@eienf
eienf / NSInteger.m
Created April 10, 2015 08:38
printf format string for NSInteger
#import <Foundation/Foundation.h>
int main(int argc, const char * argv[]) {
@autoreleasepool {
NSInteger i = 101;
NSLog(@"NSInteger %lu",sizeof(NSInteger));
NSLog(@"long %lu",sizeof(long));
NSLog(@"int %lu",sizeof(int));
NSLog(@"%ld",(long)i);
}
@eienf
eienf / makeIcons.sh
Created March 6, 2015 17:11
Create various sizes of iPhone app icons with sips command.
#!/bin/sh
if [ $# -lt 1 ]; then
echo "Uage: $0 ImageFileName"
exit 1
fi
FILE=$1
BASENAME=${FILE%.*}
EXT=${FILE##*.}
DIR=icons
@eienf
eienf / CamelCase.m
Created June 22, 2013 13:12
convert camel case to/from snake case in Objective-C.
#import <Foundation/Foundation.h>
NSString *toCamelCase(NSString *s)
{
return [[[s capitalizedString] componentsSeparatedByCharactersInSet:[[NSCharacterSet characterSetWithCharactersInString:@"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"] invertedSet]] componentsJoinedByString:@""];
}
NSString *splitOnCapital(NSString *s) {
NSRange upcaseRange = NSMakeRange('A', 26);
NSRange numberRange = NSMakeRange('0', 10);
class Convert2 {
public static void main(String args[]) {
if ( args.length < 2 ) {
throw new IllegalArgumentException("parameter : number_string radix");
}
String s = args[0];
int radix = Integer.parseInt(args[1]);
int decimal = Integer.parseInt(s,radix);
System.out.println("result = "+decimal);
}
@eienf
eienf / Convert.java
Created May 16, 2013 15:46
convert Input : decimal number to the specific radix number string.
class Convert {
public static void main(String args[]) {
if ( args.length < 2 ) {
throw new IllegalArgumentException("parameter : decimal radix");
}
int decimal = Integer.parseInt(args[0]);
int radix = Integer.parseInt(args[1]);
String s = Integer.toString(decimal,radix);
System.out.println("result = "+s);
}
@eienf
eienf / Decimal.java
Created May 15, 2013 08:49
Algorithm for convert binary string to decimal integer.
class Decimal {
public static long toLong(String bin) {
long decimal = 0;
for ( int i = 0; i < bin.length(); i++ ) {
if ( bin.substring(i,i+1).equals("1") ) {
decimal <<= 1;
decimal += 1;
} else if ( bin.substring(i,i+1).equals("0") ) {
decimal <<= 1;
} else if ( bin.substring(i,i+1).equals(" ") ) {
@eienf
eienf / bin2dec.c
Last active October 29, 2023 08:58
from binary string to decimal integer.
#include <stdio.h>
#include <stdlib.h>
unsigned long bin2dec(const char *binary)
{
unsigned long decimal = 0;
do {
if ( *binary == '0' ) {
decimal <<= 1;
} else if ( *binary == '1' ) {
@eienf
eienf / time_dec2bin.c
Last active December 17, 2015 05:48
Time mesurement for decimal to binary change function.
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <time.h>
#include <mach/mach_time.h>
#define DEBUG 0
int digit3(unsigned long n)
{