Googleからchromeのrpmをダウンロードしてインストールしようとしても,Fedora18ではMissing Security Signaturesというエラーが出てインストールできない.
仕方がないので以下のサイトからrpmをrpmコマンドから直にダウンロードしてインストールする.
rpm -ivh https://dl.google.com/linux/direct/google-chrome-stable_current_i386.rpm
rpm -ivh https://dl.google.com/linux/direct/google-chrome-stable_current_i386.rpm
#include <iostream> #include <cstdlib> #include <vector> using namespace std; void ShowIntVal(void* param); void ShowValFromVector(void* param); void (*pShowValFunc)(void* param); int main() { // int val pShowValFunc = ShowIntVal; int val = 32; pShowValFunc((void*)&val); vector<int> v; v.push_back(-20); v.push_back(-2000); pShowValFunc = ShowValFromVector; pShowValFunc((void*)&v); return EXIT_SUCCESS; } void ShowIntVal(void* param){ int* pIntVal = static_cast<int*>(param); cout << "ShowIntVal:" << *pIntVal << endl; } void ShowValFromVector(void* param){ vector<int> *pV = static_cast<vector<int>*>(param); vector<int>::iterator iter; cout << "ShowValFromVector:"; for( iter = pV->begin(); iter != pV->end();iter++) cout << *iter << ' '; cout << endl; }
#include <iostream> #include <ctime> using namespace std; class IDGenerator; class IDGenerator { private: int max; IDGenerator(long,int); public: static IDGenerator& GetInstance(long,int); ~IDGenerator(); int Next(); }; IDGenerator::IDGenerator(long seed,int maxVal):max(maxVal) { srand(seed); } IDGenerator::~IDGenerator(){} IDGenerator& IDGenerator::GetInstance(long seed,int maxVal){ static IDGenerator gen(seed,maxVal); return gen; } int IDGenerator::Next() { return rand() % max; } int main() { IDGenerator idGen = IDGenerator::GetInstance(time(NULL),100); for(int i = 0;i < 20;i++ ) { cout << idGen.Next() << " "; } return EXIT_SUCCESS; }
#include <cstdio> #include <string> using namespace std; class Base { protected: int fieldA; public: Base() { fieldA = 0;}; virtual void ShowField(const string* prefix ) { printf("%s-%d\n", prefix->c_str(), fieldA); } }; class Child: public Base { public: Child(); void ShowField(const string* prefix); }; Child::Child(): Base() { printf("Child created.\n"); } void Child::ShowField(const string* prefix) { Base::ShowField( prefix ); string* p = const_cast<string*>(prefix); *p = "--the jail breaker--"; } class Stranger { public: Stranger() {} }; int main() { // static_cast double d = 50.0; printf( "staticcast - %d\n", static_cast<int>(d) ); // const_cast Child c; string str = "abc"; c.ShowField(&str); printf("%s\n",str.c_str()); // dynamic_cast Stranger *pS = dynamic_cast<Stranger*>(&c); if( pS == NULL ) printf("downcast failed as per the pS content"); return 0; }
staticcast - 50 Child created. abc-0 --the jail breaker-- downcast failed as per the pS content
#include <iostream> #include <cstdlib> #include <vector> #include <string> using namespace std; class TradeInfo { protected: string tradeId; int eventId; public: TradeInfo() {} virtual ~TradeInfo() {} TradeInfo(const TradeInfo& info) { tradeId = info.tradeId; eventId = info.eventId; } TradeInfo& operator =(const TradeInfo& info) { TradeInfo in; in.tradeId = info.tradeId; in.eventId = info.eventId; return in; } string GetTradeId() { return tradeId; } int GetEventId() { return eventId; } void SetTradeId(string str) { tradeId = str; } void SetEventid(int evt) { eventId = evt; } void dump() { cout << "TradeId-" << tradeId << ",EventId-" << eventId << endl; } }; TradeInfo GenerateTradeInfo(string str,int eventId) { TradeInfo t; t.SetTradeId(str); t.SetEventid(eventId); return t; } int main() { vector<TradeInfo> v; v.push_back(GenerateTradeInfo("abc",1)); TradeInfo t = v.at(0); t.dump(); return EXIT_SUCCESS; }
#include <iostream> #include <iostream> #include <cstdlib> #include <vector> #include <string> using namespace std; class Parent { protected: vector<int> v; public: Parent(){ cout << "constructor" << endl; } virtual ~Parent() { cout << "Destructor" << endl; } virtual void push_back(int a){ v.push_back(a); } //virtual void push_back(int a){ v.push_back(a); } virtual int get(int idx){ return v.at(idx); } }; class Child: public Parent { private: string decoration; public: Child(string decorationVal="empty") { decoration = decorationVal; } int get(int idx){ cout << "**" << decoration << "**" << endl; return v.at(idx); } }; int main() { Parent *p = new Child(string("takoneko")); p->push_back(32); p->push_back(16); cout << p->get(0) << endl; return 0; }
public class Deadlock { Object critA = new Object(); Object critB = new Object(); int a; int b; public void start() throws Exception { a = 100; b = 50; Thread a = new Thread( new CriticalSectionLogic(), "A" ); Thread b = new Thread( new CriticalSectionLogic(), "B" ); a.start(); Thread.sleep( 100 ); b.start(); } /** * @param args */ public static void main(String[] args) throws Exception { Deadlock d = new Deadlock(); d.start(); } public void criticalSectionA( String name ) throws Exception { synchronized( critA ) { System.out.printf( "%s entering into CSA\n", name ); synchronized( critB ) { Thread.sleep( 100 ); b += a; } a = 0; System.out.printf( "%s exitting into CSA\n", name ); } } public void criticalSectionB( String name ) throws Exception { synchronized( critB ) { System.out.printf( "%s entering into CSB\n", name ); synchronized( critA ) { a += b; } b = 0; System.out.printf( "%s exitting into CSB\n", name ); } } class CriticalSectionLogic implements Runnable { public void run() { String name = Thread.currentThread().getName(); System.out.printf( "Thread %s starting..\n", name ); try { if( name.equals( "A" ) ) { criticalSectionA( name ); criticalSectionB( name ); } else { criticalSectionB( name ); criticalSectionA( name ); } } catch ( Exception e ) { e.printStackTrace(); } } } }
Thread A starting.. A entering into CSA Thread B starting.. A exitting into CSA B entering into CSB B exitting into CSB B entering into CSA A entering into CSB
@Test(expected=Exception.class) public void testCompositeMap() { CompositeMap compo = new CompositeMap( initMap(), initMap2() ); assertThat( compo.size(), is( 10 ) ); compo = new CompositeMap( initMap(), initMap() ); } private Map<Integer,String> initMap() { Map<Integer,String> m = new HashMap<Integer,String>(); m.put( 1, "NewYork" ); m.put( 2, "Tokyo" ); m.put( 3, "Bangalore" ); m.put( 4, "London" ); m.put( 5, "Paris" ); return m; } private Map<Integer,String> initMap2() { Map<Integer,String> m = new HashMap<Integer,String>(); m.put( 6, "Hongkong" ); m.put( 7, "Seoul" ); m.put( 8, "Cairo" ); m.put( 9, "AllenTown" ); m.put( 10, "GeorgeTown" ); return m; }
import java.util.ArrayList; import java.util.List; import java.util.Random; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; import java.util.concurrent.TimeUnit; import org.apache.commons.collections.FastArrayList; import org.apache.commons.lang3.time.StopWatch; import org.junit.Before; import org.junit.Test; import static org.junit.Assert.*; import static org.hamcrest.CoreMatchers.*; public class FastListTest implements Runnable { List<String> list = null; @Before public void init() { list = initFastList(); } @Test public void testFastList() throws InterruptedException { ExecutorService service = Executors.newFixedThreadPool( 30 ); StopWatch watch = new StopWatch(); watch.start(); for( int i = 0;i < 100;i++ ) { service.submit( this ); } service.shutdown(); service.awaitTermination( 10000L, TimeUnit.HOURS ); System.out.println( "FAST - " + watch.getTime() ); watch.reset(); list = initArrayList(); service = Executors.newFixedThreadPool( 30 ); watch.start(); for( int i = 0;i < 100;i++ ) { service.submit( this ); } service.shutdown(); service.awaitTermination( 10000L, TimeUnit.HOURS ); System.out.println( "NONFAST - " + watch.getTime() ); } private FastArrayList initFastList() { // slow mode first FastArrayList list = new FastArrayList(); list.add( "a" ); // switching to fast mode list.setFast( true ); return list; } private List<String> initArrayList() { // slow mode first List<String> list = new ArrayList<String>(); list.add( "a" ); // switching to fast mode return list; } public void run() { // access to random node list.get( 0 ); } }
import java.util.Comparator; import org.apache.commons.collections.ArrayStack; import org.apache.commons.collections.Buffer; import org.apache.commons.collections.buffer.PriorityBuffer; import org.apache.commons.collections.buffer.UnboundedFifoBuffer; import org.junit.Test; import static org.junit.Assert.*; import static org.hamcrest.CoreMatchers.*; public class CollectionsTest { @Test public void testBuffer() { // Queue - FIFO Buffer buffer = new UnboundedFifoBuffer(); injectTestValue( buffer ); assertThat( (String)buffer.get(), is( "1st" ) ); assertThat( (String)buffer.remove(), is( "1st" ) ); assertThat( (String)buffer.remove(), is( "2nd" ) ); assertThat( (String)buffer.remove(), is( "3rd" ) ); // Stack - LIFO buffer = new ArrayStack(); injectTestValue( buffer ); assertThat( (String)buffer.get(), is( "3rd" ) ); assertThat( (String)buffer.remove(), is( "3rd" ) ); assertThat( (String)buffer.remove(), is( "2nd" ) ); assertThat( (String)buffer.remove(), is( "1st" ) ); // BinaryHeap // ascending buffer = new PriorityBuffer( true, new StringLengthComparator<String>() ); injectTestValueForPriorityBuffer( buffer ); assertThat( (String)buffer.remove(), is( "/usr" ) ); assertThat( (String)buffer.remove(), is( "/usr/local" ) ); assertThat( (String)buffer.remove(), is( "/usr/local/bin" ) ); // descending buffer = new PriorityBuffer( false, new StringLengthComparator<String>() ); injectTestValueForPriorityBuffer( buffer ); assertThat( (String)buffer.remove(), is( "/usr/local/bin" ) ); assertThat( (String)buffer.remove(), is( "/usr/local" ) ); assertThat( (String)buffer.remove(), is( "/usr" ) ); } private void injectTestValue( Buffer buffer ) { buffer.add( "1st" ); buffer.add( "2nd" ); buffer.add( "3rd" ); } private void injectTestValueForPriorityBuffer( Buffer buffer ) { buffer.add( "/usr" ); buffer.add( "/usr/local" ); buffer.add( "/usr/local/bin" ); } } class StringLengthComparator<String> implements Comparator<String> { public int compare( String arg0, String arg1 ) { if( ((java.lang.String) arg0).length() > ((java.lang.String) arg1).length() ) return 1; else if( ((java.lang.String) arg0).length() == ((java.lang.String) arg1).length() ) return 0; else return -1; } }
@Test public void testBidiMap() { BidiMap bidiMap = new TreeBidiMap( initMap() ); assertThat( (String)bidiMap.remove( 4 ), is( "London" ) ); assertThat( ((Integer)bidiMap.removeValue( "NewYork" )).intValue(), is( 1 ) ); assertThat( bidiMap.size(), is( 3 ) ); } private Map<Integer,String> initMap() { Map<Integer,String> m = new HashMap<Integer,String>(); m.put( 1, "NewYork" ); m.put( 2, "Tokyo" ); m.put( 3, "Bangalore" ); m.put( 4, "London" ); m.put( 5, "Paris" ); return m; }
@Test public void testBag() { Bag bag = new HashBag(); bag.add( 4, 6 ); bag.remove( 4, 3 ); assertThat( bag.getCount( 4 ), is( 3 ) ); Iteratoriter = bag.iterator(); while( iter.hasNext() ) { System.out.println( System.identityHashCode( iter.next() ) ); } }
@Test public void testMapIteration() { Map<Integer,String> map = initMap(); Iterator<Entry<Integer,String>> entSet = map.entrySet().iterator(); while( entSet.hasNext() ) { Entry<Integer,String> e = entSet.next(); System.out.printf( "%d-%s\n", e.getKey(), e.getValue() ); } } private Map<Integer,String> initMap() { Map<Integer,String> m = new HashMap<Integer,String>(); m.put( 1, "NewYork" ); m.put( 2, "Tokyo" ); m.put( 3, "Bangalore" ); m.put( 4, "London" ); m.put( 5, "Paris" ); return m; }
/** * Order not stable. Result is like .. * <pre> * 2Tokyo * 4London * 1NewYork * 3Bangalore * 5Paris * </pre> */ @Test public void testIterableMap() { IterableMap map = new HashedMap( initMap() ); MapIterator iter = map.mapIterator(); String val = null; int key = 0; while( iter.hasNext() ) { iter.next(); key = ((Integer)iter.getKey()).intValue(); val = (String)iter.getValue(); System.out.printf("%d%s\n",key, val); }
} private Map<Integer,String> initMap() { Map<Integer,String> m = new HashMap<Integer,String>(); m.put( 1, "NewYork" ); m.put( 2, "Tokyo" ); m.put( 3, "Bangalore" ); m.put( 4, "London" ); m.put( 5, "Paris" ); return m; }
@SuppressWarnings("unchecked") @Test public void testOrderedMap() { OrderedMap map = new LinkedMap( initMap() ); MapIterator iter = map.mapIterator(); String val = null; int key = 0; while( iter.hasNext() ) { iter.next(); key = ((Integer)iter.getKey()).intValue(); val = (String)iter.getValue(); System.out.println(key + val); } map.clear(); map.put( 1, "Metuchen" ); map.put( 3, "Kosciuszko" ); map.put( 2, "Kitami" ); map.put( 5, "Tripoli" ); map.put( 4, "Serangoon" ); assertThat( ((Integer)map.firstKey()).intValue(), is( 1 ) ); assertThat( (String)map.get(map.firstKey()), is( "Metuchen" ) ); assertThat( ((Integer)map.nextKey(3)).intValue(), is( 2 ) ); assertThat( (String)map.get(map.nextKey(3)), is( "Kitami" ) ); } private Map<Integer,String> initMap() { Map<Integer,String> m = new HashMap<Integer,String>(); m.put( 1, "NewYork" ); m.put( 2, "Tokyo" ); m.put( 3, "Bangalore" ); m.put( 4, "London" ); m.put( 5, "Paris" ); return m; }
#include <iostream> #include <cstdlib> using namespace std; static char arrA[] = { 'A','B','B','E','G', 'K', 'U' }; static char arrB[] = { 'C','D','E','F','G', 'K', 'V','Z' }; void dump(char* arr, int size){ for(int i = 0;i < size;i++){ cout << arr[i] << ' '; } cout << endl; } void my_bsearch(char arr[], char target, int* idx){ cout << "bsearching.." << endl; int min = 0; int max = sizeof(arrB)/sizeof(char) - 1; char midVal; while(min <= max){ midVal = arrB[(min + max) / 2]; cout << target << ',' << min << ',' << max << ',' << midVal << ',' << (min + max)/2 << endl; if(midVal == target) { arr[*idx] = midVal; *idx += 1; return; } else if(midVal < target) min = (min + max)/2 + 1; else max = (min + max)/2 - 1; } } int main() { char ansArr[100]; int delta = 0; int idx = 0; for(int i = 0;i < sizeof(arrA)/sizeof(char);i++){ my_bsearch(ansArr, arrA[i], &idx); } cout << "idx.." << idx << endl; dump(ansArr, idx); return EXIT_SUCCESS; }