swap

Can I swap colors in image using GD library in PHP?

廉价感情. 提交于 2019-11-26 16:37:28
问题 I got the image like this (it's a graph): (source: kitconet.com) I want to change the colours, so the white is black, the graph line is light blue, etc.. is it possible to achieve with GD and PHP? 回答1: This will replace the white color with Gray $imgname = "test.gif"; $im = imagecreatefromgif ($imgname); $index = imagecolorclosest ( $im, 255,255,255 ); // get White COlor imagecolorset($im,$index,92,92,92); // SET NEW COLOR $imgname = "result.gif"; imagegif($im, $imgname ); // save image as

Can I tell Linux not to swap out a particular processes' memory?

别来无恙 提交于 2019-11-26 15:43:52
问题 Is there a way to tell Linux that it shouldn't swap out a particular processes' memory to disk? Its a Java app, so ideally I'm hoping for a way to do this from the command line. I'm aware that you can set the global swappiness to 0, but is this wise? 回答1: You can do this via the mlockall(2) system call under Linux; this will work for the whole process, but do read about the argument you need to pass. Do you really need to pull the whole thing in-core? If it's a java app, you would presumably

How to write a basic swap function in Java [duplicate]

一笑奈何 提交于 2019-11-26 15:07:36
This question already has an answer here: Java method to swap primitives 7 answers I am new to java. How to write the java equivalent of the following C code. void Swap(int *p, int *q) { int temp; temp = *p; *p = *q; *q = temp; } Here is one trick: public static int getItself(int itself, int dummy) { return itself; } public static void main(String[] args) { int a = 10; int b = 20; a = getItself(b, b = a); } Sorting two ints The short answer is: you can't do that, java has no pointers. But here's something similar that you can do: public void swap(AtomicInteger a, AtomicInteger b){ // look mom,

Swap nodes in a singly-linked list

↘锁芯ラ 提交于 2019-11-26 14:17:30
问题 I am trying to swap two nodes. For example if the nodes are a and b I am passing the pointers (a-1)->next and (b-1)->next which are basically nodes a and b . void swap(struct stack **a,struct stack **b) { struct stack *temp1 = *a, *temp2 = *b, *temp3 = *b; *a = *b; (*b)->next = (temp1)->next; temp2 = temp1; (temp2)->next = temp3->next; } What am I doing wrong? When I am trying to print the nodes after calling the function it's an infinite loop. Please help. 回答1: Why Infinite loop? Infinite

Swap two items in List<T>

喜夏-厌秋 提交于 2019-11-26 12:43:47
问题 Is there a LINQ way to swap the position of two items inside a list<T> ? 回答1: Check the answer from Marc from C#: Good/best implementation of Swap method. public static void Swap<T>(IList<T> list, int indexA, int indexB) { T tmp = list[indexA]; list[indexA] = list[indexB]; list[indexB] = tmp; } which can be linq-i-fied like public static IList<T> Swap<T>(this IList<T> list, int indexA, int indexB) { T tmp = list[indexA]; list[indexA] = list[indexB]; list[indexB] = tmp; return list; } var lst

how to provide a swap function for my class?

眉间皱痕 提交于 2019-11-26 12:03:35
What is the proper way to enable my swap in STL algorithms? 1) Member swap . Does std::swap use SFINAE trick to use the member swap . 2) Free standing swap in the same namespace. 3) Partial specialization of std::swap . 4) All of the above. Thank you. EDIT: Looks like I didn't word my question clearly. Basically, I have a template class and I need STL algos to use the (efficient) swap method I wrote for that class. 1) is the proper use of swap . Write it this way when you write "library" code and want to enable ADL (argument-dependent lookup) on swap . Also, this has nothing to do with SFINAE.

Swap two variables without using a temporary variable

江枫思渺然 提交于 2019-11-26 11:44:32
I'd like to be able to swap two variables without the use of a temporary variable in C#. Can this be done? decimal startAngle = Convert.ToDecimal(159.9); decimal stopAngle = Convert.ToDecimal(355.87); // Swap each: // startAngle becomes: 355.87 // stopAngle becomes: 159.9 Willem Van Onsem First of all, swapping without a temporary variable in a language as C# is a very bad idea . But for the sake of answer, you can use this code: startAngle = startAngle + stopAngle; stopAngle = startAngle - stopAngle; startAngle = startAngle - stopAngle; Problems can however occur with rounding off if the two

How to swap two variables in JavaScript

早过忘川 提交于 2019-11-26 11:33:50
I have this two variables: var a = 1, b = 2; My question is how to swap them? Only this variables, not any objects. Here's a one-liner to swap the values of two variables. Given variables a and b : b = [a, a = b][0]; Demonstration below: var a=1, b=2, output=document.getElementById('output'); output.innerHTML="<p>Original: "+a+", "+b+"</p>"; b = [a, a = b][0]; output.innerHTML+="<p>Swapped: "+a+", "+b+"</p>"; <div id="output"></div> Pedro Justo ES6 (Firefox and Chrome already support it (Destructuring Assignment Array Matching)): let a = 5, b = 6; [a, b] = [b, a]; console.log(`${a} ${b}`); You

Why is this statement not working in java x ^= y ^= x ^= y;

拥有回忆 提交于 2019-11-26 11:17:51
问题 int x=1; int y=2; x ^= y ^= x ^= y; I am expecting the values to be swapped.But it gives x=0 and y=1. when i tried in C language it gives the correct result. 回答1: Your statement is roughly equivalent to this expanded form: x = x ^ (y = y ^ (x = x ^ y)); Unlike in C, in Java the left operand of a binary operator is guaranteed to be evaluated before the right operand. Evaluation occurs as follows: x = x ^ (y = y ^ (x = x ^ y)) x = 1 ^ (y = 2 ^ (x = 1 ^ 2)) x = 1 ^ (y = 2 ^ (x = 3)) x = 1 ^ (y =

Swap rows with columns (transposition) of a matrix in javascript [duplicate]

痴心易碎 提交于 2019-11-26 08:35:49
This question already has an answer here: Transposing a 2D-array in JavaScript 17 answers For instance I have a matrix like this: |1 2 3| |4 5 6| |7 8 9| and I need it to convert into a matrix like this: |1 4 7| |2 5 8| |3 6 9| What is the best and optimal way to achieve this goal? troynt See article: Transpose An Array In JavaScript and jQuery function transpose(a) { // Calculate the width and height of the Array var w = a.length || 0; var h = a[0] instanceof Array ? a[0].length : 0; // In case it is a zero matrix, no transpose routine needed. if(h === 0 || w === 0) { return []; } /** * @var