qid
int64
1
74.7M
question
stringlengths
22
28.7k
date
stringlengths
10
10
metadata
sequence
response_j
stringlengths
24
26.4k
response_k
stringlengths
25
24.2k
10,430,706
I have created a WCF service interface and implementation in a Class Library. I haven't yet decided if the service will be self-hosted or hosted by a Windows Service. How do I now create a console app (seperate project in Visual Studio) that will host my WCF service ? I know I can host it by programatically typing in all the configuration (like [here](http://msdn.microsoft.com/en-us/library/ms731758.aspx)) but I don't want that. I want this console app to have a configuration file that has the 'serviceModel' section in it already, so that all I will have to do in the Main function of the console app would be something like: ``` MyService service = new MyService(); service.Open(); ``` And so 'Open' will read the configuration from the 'App.config' file.
2012/05/03
[ "https://Stackoverflow.com/questions/10430706", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1335129/" ]
The referer is unfortunatly set BY the client and some browser (or plugins) allow the user to edit what referer is sent to the server. It's never a good idea to trust "critical" (in your case I guess) informations sent by the user. However this is the only information you have regarding where the user comes from (if you decide not to use what paypal can offer).
You can use `document.referrer` in javascript and send that to the server through ajax or something if you need
10,430,706
I have created a WCF service interface and implementation in a Class Library. I haven't yet decided if the service will be self-hosted or hosted by a Windows Service. How do I now create a console app (seperate project in Visual Studio) that will host my WCF service ? I know I can host it by programatically typing in all the configuration (like [here](http://msdn.microsoft.com/en-us/library/ms731758.aspx)) but I don't want that. I want this console app to have a configuration file that has the 'serviceModel' section in it already, so that all I will have to do in the Main function of the console app would be something like: ``` MyService service = new MyService(); service.Open(); ``` And so 'Open' will read the configuration from the 'App.config' file.
2012/05/03
[ "https://Stackoverflow.com/questions/10430706", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1335129/" ]
You can use `document.referrer` in javascript and send that to the server through ajax or something if you need
Looking at this from a different persepective: If you are trying out find outwhere they came from before they went to PayPal, and you're site is sending them to PayPal (or you can get them to redirect via your website on the way to PayPal), set a cookie on your website before you redirect them, and then read the cookie when they return. Sorry if again not what you need, but just checking you've considered it (as I also don't think you're going to win with the referrer).
10,430,706
I have created a WCF service interface and implementation in a Class Library. I haven't yet decided if the service will be self-hosted or hosted by a Windows Service. How do I now create a console app (seperate project in Visual Studio) that will host my WCF service ? I know I can host it by programatically typing in all the configuration (like [here](http://msdn.microsoft.com/en-us/library/ms731758.aspx)) but I don't want that. I want this console app to have a configuration file that has the 'serviceModel' section in it already, so that all I will have to do in the Main function of the console app would be something like: ``` MyService service = new MyService(); service.Open(); ``` And so 'Open' will read the configuration from the 'App.config' file.
2012/05/03
[ "https://Stackoverflow.com/questions/10430706", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1335129/" ]
You can examine IPN. It sends notification when a transaction is affected. URL : <https://www.paypal.com/ipn>
Looking at this from a different persepective: If you are trying out find outwhere they came from before they went to PayPal, and you're site is sending them to PayPal (or you can get them to redirect via your website on the way to PayPal), set a cookie on your website before you redirect them, and then read the cookie when they return. Sorry if again not what you need, but just checking you've considered it (as I also don't think you're going to win with the referrer).
10,430,706
I have created a WCF service interface and implementation in a Class Library. I haven't yet decided if the service will be self-hosted or hosted by a Windows Service. How do I now create a console app (seperate project in Visual Studio) that will host my WCF service ? I know I can host it by programatically typing in all the configuration (like [here](http://msdn.microsoft.com/en-us/library/ms731758.aspx)) but I don't want that. I want this console app to have a configuration file that has the 'serviceModel' section in it already, so that all I will have to do in the Main function of the console app would be something like: ``` MyService service = new MyService(); service.Open(); ``` And so 'Open' will read the configuration from the 'App.config' file.
2012/05/03
[ "https://Stackoverflow.com/questions/10430706", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1335129/" ]
In case your site uses HTTP (not HTTPS) and PayPal uses HTTPS, there is no Referrer being sent! [HTTP RFC - 15.1.3 Encoding Sensitive Information in URI's](https://www.rfc-editor.org/rfc/rfc2616#section-15.1.3) states: > > Clients SHOULD NOT include a Referer header field in a (non-secure) > HTTP request if the referring page was transferred with a secure > protocol. > > > So the only way to get the Referrer is to use HTTPS on your site.
The referer is unfortunatly set BY the client and some browser (or plugins) allow the user to edit what referer is sent to the server. It's never a good idea to trust "critical" (in your case I guess) informations sent by the user. However this is the only information you have regarding where the user comes from (if you decide not to use what paypal can offer).
10,430,706
I have created a WCF service interface and implementation in a Class Library. I haven't yet decided if the service will be self-hosted or hosted by a Windows Service. How do I now create a console app (seperate project in Visual Studio) that will host my WCF service ? I know I can host it by programatically typing in all the configuration (like [here](http://msdn.microsoft.com/en-us/library/ms731758.aspx)) but I don't want that. I want this console app to have a configuration file that has the 'serviceModel' section in it already, so that all I will have to do in the Main function of the console app would be something like: ``` MyService service = new MyService(); service.Open(); ``` And so 'Open' will read the configuration from the 'App.config' file.
2012/05/03
[ "https://Stackoverflow.com/questions/10430706", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1335129/" ]
In case your site uses HTTP (not HTTPS) and PayPal uses HTTPS, there is no Referrer being sent! [HTTP RFC - 15.1.3 Encoding Sensitive Information in URI's](https://www.rfc-editor.org/rfc/rfc2616#section-15.1.3) states: > > Clients SHOULD NOT include a Referer header field in a (non-secure) > HTTP request if the referring page was transferred with a secure > protocol. > > > So the only way to get the Referrer is to use HTTPS on your site.
Thanks for your enlightment (in the comment). As Bob stated, you cannot rely on the information sent by the server. What I would do, is create a page an user has to go to before the payment, set a cookie (or session), redirect the user to the PayPal website. When the user returns to your website (either through PayPal, some links, or manually) you know the person hit the Pay button (as you set the cookie or session) and perform the actions you want to. It's not what you asked, but might be an acceptable workaround.
10,430,706
I have created a WCF service interface and implementation in a Class Library. I haven't yet decided if the service will be self-hosted or hosted by a Windows Service. How do I now create a console app (seperate project in Visual Studio) that will host my WCF service ? I know I can host it by programatically typing in all the configuration (like [here](http://msdn.microsoft.com/en-us/library/ms731758.aspx)) but I don't want that. I want this console app to have a configuration file that has the 'serviceModel' section in it already, so that all I will have to do in the Main function of the console app would be something like: ``` MyService service = new MyService(); service.Open(); ``` And so 'Open' will read the configuration from the 'App.config' file.
2012/05/03
[ "https://Stackoverflow.com/questions/10430706", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1335129/" ]
Quoted from [PHP.net](http://php.net/manual/en/reserved.variables.server.php): > > $\_SERVER is an array containing information such as headers, paths, and script locations. The >entries in this array are created by the web server. There is no guarantee that every web >server will provide any of these; servers may omit some, or provide others not listed here. > > >
You can use `document.referrer` in javascript and send that to the server through ajax or something if you need
10,430,706
I have created a WCF service interface and implementation in a Class Library. I haven't yet decided if the service will be self-hosted or hosted by a Windows Service. How do I now create a console app (seperate project in Visual Studio) that will host my WCF service ? I know I can host it by programatically typing in all the configuration (like [here](http://msdn.microsoft.com/en-us/library/ms731758.aspx)) but I don't want that. I want this console app to have a configuration file that has the 'serviceModel' section in it already, so that all I will have to do in the Main function of the console app would be something like: ``` MyService service = new MyService(); service.Open(); ``` And so 'Open' will read the configuration from the 'App.config' file.
2012/05/03
[ "https://Stackoverflow.com/questions/10430706", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1335129/" ]
The referer is unfortunatly set BY the client and some browser (or plugins) allow the user to edit what referer is sent to the server. It's never a good idea to trust "critical" (in your case I guess) informations sent by the user. However this is the only information you have regarding where the user comes from (if you decide not to use what paypal can offer).
Looking at this from a different persepective: If you are trying out find outwhere they came from before they went to PayPal, and you're site is sending them to PayPal (or you can get them to redirect via your website on the way to PayPal), set a cookie on your website before you redirect them, and then read the cookie when they return. Sorry if again not what you need, but just checking you've considered it (as I also don't think you're going to win with the referrer).
10,430,706
I have created a WCF service interface and implementation in a Class Library. I haven't yet decided if the service will be self-hosted or hosted by a Windows Service. How do I now create a console app (seperate project in Visual Studio) that will host my WCF service ? I know I can host it by programatically typing in all the configuration (like [here](http://msdn.microsoft.com/en-us/library/ms731758.aspx)) but I don't want that. I want this console app to have a configuration file that has the 'serviceModel' section in it already, so that all I will have to do in the Main function of the console app would be something like: ``` MyService service = new MyService(); service.Open(); ``` And so 'Open' will read the configuration from the 'App.config' file.
2012/05/03
[ "https://Stackoverflow.com/questions/10430706", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1335129/" ]
Thanks for your enlightment (in the comment). As Bob stated, you cannot rely on the information sent by the server. What I would do, is create a page an user has to go to before the payment, set a cookie (or session), redirect the user to the PayPal website. When the user returns to your website (either through PayPal, some links, or manually) you know the person hit the Pay button (as you set the cookie or session) and perform the actions you want to. It's not what you asked, but might be an acceptable workaround.
You can use `document.referrer` in javascript and send that to the server through ajax or something if you need
10,430,706
I have created a WCF service interface and implementation in a Class Library. I haven't yet decided if the service will be self-hosted or hosted by a Windows Service. How do I now create a console app (seperate project in Visual Studio) that will host my WCF service ? I know I can host it by programatically typing in all the configuration (like [here](http://msdn.microsoft.com/en-us/library/ms731758.aspx)) but I don't want that. I want this console app to have a configuration file that has the 'serviceModel' section in it already, so that all I will have to do in the Main function of the console app would be something like: ``` MyService service = new MyService(); service.Open(); ``` And so 'Open' will read the configuration from the 'App.config' file.
2012/05/03
[ "https://Stackoverflow.com/questions/10430706", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1335129/" ]
Thanks for your enlightment (in the comment). As Bob stated, you cannot rely on the information sent by the server. What I would do, is create a page an user has to go to before the payment, set a cookie (or session), redirect the user to the PayPal website. When the user returns to your website (either through PayPal, some links, or manually) you know the person hit the Pay button (as you set the cookie or session) and perform the actions you want to. It's not what you asked, but might be an acceptable workaround.
Looking at this from a different persepective: If you are trying out find outwhere they came from before they went to PayPal, and you're site is sending them to PayPal (or you can get them to redirect via your website on the way to PayPal), set a cookie on your website before you redirect them, and then read the cookie when they return. Sorry if again not what you need, but just checking you've considered it (as I also don't think you're going to win with the referrer).
54,930,044
Everywhere I look online, I see people posting on how to successfully crop an image. However, I want to 'crop'/ clear a hole out of an image. I want to keep the original image, but crop out a rectangle [![enter image description here](https://i.stack.imgur.com/uJXbm.jpg)](https://i.stack.imgur.com/uJXbm.jpg) As you can see in the image above, I have "cropped" out the kittens face. I maintained the original image, but removed only part of it. I cannot figure out how to do that.
2019/02/28
[ "https://Stackoverflow.com/questions/54930044", "https://Stackoverflow.com", "https://Stackoverflow.com/users/7635909/" ]
Assuming you want to replace the original pixel colors with transparency you run into a small problem: You **can't draw or fill with transparency** in GDI+. But **you can** use `Graphics.Clear(Color.Transparent)`. To do that you **restrict** the region where the `Graphics` object will draw. Here we can use the simple cropping rectangle but you can clear more complex shapes using a `GraphicsPath`.. Example using a bitmap `bmp`: ``` using (Graphics g = Graphics.FromImage(bmp)) { Rectangle crop = new Rectangle(222,222,55,55); g.SetClip(crop); g.Clear(Color.Transparent); } bmp.Save(somefilename, ImageFormat.Png); ```
Setting your `Graphics` object's `CompositingMode` property to `CompositingMode.SourceCopy` will allow your drawing operations to replace the alpha value instead of proportionally opacifying it: ```cs public static void TestDrawTransparent() { //This code will, successfully, draw something transparent overwriting an opaque area. //More precisely, it creates a 100*100 fully-opaque red square with a 50*50 semi-transparent center. using(Bitmap bmp = new Bitmap(100, 100, PixelFormat.Format32bppArgb)) { using(Graphics g = Graphics.FromImage(bmp)) using(Brush opaqueRedBrush = new SolidBrush(Color.FromArgb(255, 255, 0, 0))) using(Brush semiRedBrush = new SolidBrush(Color.FromArgb(128, 255, 0, 0))) { g.Clear(Color.Transparent); Rectangle bigRect = new Rectangle(0, 0, 100, 100); Rectangle smallRect = new Rectangle(25, 25, 50, 50); g.CompositingMode = System.Drawing.Drawing2D.CompositingMode.SourceCopy; g.FillRectangle(opaqueRedBrush, bigRect); g.FillRectangle(semiRedBrush, smallRect); } bmp.Save(@"C:\FilePath\TestDrawTransparent.png", ImageFormat.Png); } } ``` In this code, I first draw a fully-opaque red square, then a semi-transparent red square "over" it. The result is a semi-transparent "hole" in the square: [![Red square with semi-transparent center](https://i.stack.imgur.com/8M1U0.png)](https://i.stack.imgur.com/8M1U0.png) And on a black background: [![The square with semi-transparent hole, on a black background](https://i.stack.imgur.com/9WW9m.png)](https://i.stack.imgur.com/9WW9m.png) A zero-opacity brush works just as well, leaving a clear hole through the image (I checked). With that in mind, you should be able to crop any shapes you want, simply by filling them with a zero-opacity brush.
277,420
I have a class called `DataPoint` that is defined like the following. Currently, it goes through each property on an object and based on the `DataPoint`, it does some formatting like padding, trimming, etc... before it will save the record to the database. The current implementation `makes a database call for each property` which is slow, so my first step is to get everything at once into an in-memory collection. What else can I do below? Is this a good candidate for a singleton since the data rarely changes and/or is it possible to cache it (if so, how)? ``` public class DataPoint { public string Name {get;set;} public string Justification {get;set;} public int MaxLength {get;set;} public string Format {get;set;} public DataPoint GetDataPoint(string name) { var dataPoint = db.Query<DataPoint>("SELECT * FROM DataPoint WHERE name = @name", new {name}).FirstOrDefault(); return dataPoint; } public T FormatObj<T>(T obj) { foreach (var propertyInfo in typeof(T).GetProperties()) { var dataPoint = GetDataPoint(propertyInfo.Name); //Do formatting on obj Properties such as setting values, etc... } return obj; } } ```
2015/03/26
[ "https://softwareengineering.stackexchange.com/questions/277420", "https://softwareengineering.stackexchange.com", "https://softwareengineering.stackexchange.com/users/151271/" ]
You can use Memory Cache. I use memory cache to cache data rarely changes or at the specific time. Here is example: ``` public static T GetCache<T>(string key, Func<T> initializer) where T : new() { if (!MemoryCache.Default.Contains(key)) { try { T data = initializer(); AddData(key, data); return (T)MemoryCache.Default[key]; } catch (Exception ex) { LogHelper.WriteError(MethodBase.GetCurrentMethod(), ex); return default(T); } } return (T)MemoryCache.Default[key]; } public static void AddData(string key, object data) { if (data == null) { return; } var cacheTime = int.Parse(ConfigurationManager.AppSettings["CachingExpiredTime"]); AddData(key, data, cacheTime); } private static void AddData(string key, object data, int cacheMinute) { if (data == null) { return; } var policy = new CacheItemPolicy { AbsoluteExpiration = DateTime.Now.AddMinutes(cacheMinute) }; MemoryCache.Default.Add(new CacheItem(key, data), policy); } ```
I would say no. A singleton is rarely the answer. If you dont believe do a quick search on singleton anti pattern. The main problem being that it is hard to unit test code which uses a singleton. A much more flexible approach is the inversion of control pattern. Basically you would would just make the class that would use your cache depend a IDataPoint instance in the constructor and then it is up the to calling point to decide how to create or reuse and which implementation of IDataPoint it wishes to provide.
50,247,756
For example I type color in Color Change TextField press the button the color changes and so I want the rgb sliders to "obtain" this colour. For example I type white and press the button sliders need to change to 255 255 255. ``` package sample; import javafx.application.Application; import javafx.beans.value.ChangeListener; import javafx.beans.value.ObservableValue; import javafx.geometry.Insets; import javafx.scene.Scene; import javafx.scene.control.Button; import javafx.scene.control.Label; import javafx.scene.control.Slider; import javafx.scene.control.TextField; import javafx.scene.layout.GridPane; import javafx.scene.paint.Color; import javafx.scene.shape.Circle; import javafx.scene.shape.StrokeType; import javafx.scene.text.Text; import javafx.stage.Stage; import java.text.DecimalFormat; public class Main extends Application { @Override public void start(Stage primaryStage) { GridPane root = new GridPane(); GridPane grid = new GridPane(); grid.setPadding(new Insets(10, 10, 10, 10)); grid.setVgap(10); grid.setHgap(70); //Circle creation Circle circle = new Circle(150, Color.rgb(0,0,0)); circle.setStrokeType(StrokeType.CENTERED); circle.setOpacity(0.5); circle.minHeight(150); circle.minWidth(170); circle.setStroke(Color.web("green")); circle.setStrokeWidth(5); //adding circle to root group root.getChildren().add(circle); //Opacity Slider Slider opacity = new Slider(); opacity.setMin(0); opacity.setValue(0.5); opacity.setMax(1); Text opacitylevel = new Text("0.5"); javafx.scene.control.Label opacityCaption = new Label("Opacity Level:"); grid.add(opacityCaption,0,1); grid.add(opacity,1,1); grid.add(opacitylevel,2,1); //Colour Change TextField colour = new TextField(); javafx.scene.control.Label Colour = new Label("Change Colour:"); grid.add(Colour,0,2); grid.add(colour,1,2); Button clbtn = new Button("Change Colour"); clbtn.setPrefSize(200,10); grid.add(clbtn,1,3); //formatting DecimalFormat df = new DecimalFormat("#.##"); opacity.valueProperty().addListener(new ChangeListener<Number>() { public void changed(ObservableValue<? extends Number> ov, Number old_val, Number new_val) { circle.setOpacity(new_val.doubleValue()); opacitylevel.setText(df.format((double)new_val)); } }); //R G B Slider R = new Slider(); R.setMin(0); R.setValue(0); R.setMax(255); Text red = new Text("0"); javafx.scene.control.Label Rt = new Label("Red:"); grid.add(Rt,0,4); grid.add(R,1,4); grid.add(red,2,4); Slider G = new Slider(); G.setMin(0); G.setValue(0); G.setMax(255); Text green = new Text("0"); javafx.scene.control.Label Gt = new Label("Green:"); grid.add(Gt,0,5); grid.add(G,1,5); grid.add(green,2,5); Slider B = new Slider(); B.setMin(0); B.setValue(0); B.setMax(255); Text blue = new Text("0"); javafx.scene.control.Label Bt = new Label("Blue:"); grid.add(Bt,0,6); grid.add(B,1,6); grid.add(blue,2,6); root.add(grid,1,0); //creating scene Scene scene = new Scene(root,800,600,Color.web("white")); //centering circle circle.setCenterX(170); circle.setCenterY(150); //Change Colour event clbtn.setOnAction(event -> { circle.setFill(Color.web(colour.getText())); }); //RGB events //red R.valueProperty().addListener(new ChangeListener<Number>() { public void changed(ObservableValue<? extends Number> ov, Number old_val, Number new_val) { red.setText("" + new_val.intValue()); circle.setFill(Color.rgb(new_val.intValue(),Integer.parseInt(green.getText()),Integer.parseInt(blue.getText()))); } }); //green G.valueProperty().addListener(new ChangeListener<Number>() { public void changed(ObservableValue<? extends Number> ov, Number old_val, Number new_val) { green.setText("" + new_val.intValue()); circle.setFill(Color.rgb(Integer.parseInt(red.getText()),new_val.intValue(),Integer.parseInt(blue.getText()))); } }); //blue B.valueProperty().addListener(new ChangeListener<Number>() { public void changed(ObservableValue<? extends Number> ov, Number old_val, Number new_val) { blue.setText("" + new_val.intValue()); circle.setFill(Color.rgb(Integer.parseInt(red.getText()),Integer.parseInt(green.getText()),new_val.intValue())); } }); primaryStage.setScene(scene); primaryStage.show(); } public static void main(String[] args) { launch(args); } } ``` I could realize it myself but I don't understand how to get red green and blue separate from web color. Button code for the easier search. ``` clbtn.setOnAction(event -> { circle.setFill(Color.web(colour.getText())); }); ```
2018/05/09
[ "https://Stackoverflow.com/questions/50247756", "https://Stackoverflow.com", "https://Stackoverflow.com/users/9754195/" ]
``` clbtn.setOnAction(event -> { Color color = Color.web(colour.getText()); R.setValue(color.getRed() * 255); G.setValue(color.getGreen() * 255); B.setValue(color.getBlue() * 255); circle.setFill(color); }); ```
``` clbtn.setOnAction(event -> { circle.setFill(Color.web(colour.getText())); Color rgb = Color.web(colour.getText()); double redd = rgb.getRed() * 255; red.setText("" + redd); R.setValue(redd); double greenn = rgb.getGreen() * 255; green.setText("" + greenn); G.setValue(greenn); double bluee = rgb.getBlue() * 255; blue.setText("" + bluee); B.setValue(greenn); }); ```
39,512,551
I am working on writing a script for Adobe Illustrator in javascript to fill objects with selected colours. I have 32 objects and 12 colour swatches. I want to fill the 32 objects using each colour twice and then fill the remainder 8 objects with a random selection. I want to fill the objects in no discernible pattern, so just looping through each object and assigning it the next swatch colour will not do. This is what I have so far, however it is not using each colour at least twice and filling at random. ``` myObjects = app.activeDocument.selection; myDocument = app.activeDocument; if (myObjects instanceof Array) { colourSwatches = myDocument.swatches.getSelected(); //if there are swatches if (colourSwatches.length != 0) { for (i = 0; i < myObjects.length; i++) { //if the selection is a path or compound path if (myObjects[i].typename == "PathItem" || myObjects[i].typename == "CompoundPathItem") { selItem = myObjects[i]; selItem.filled = true; //select colour from swatches at random and then fill swatchIndex = Math.round( Math.random() * (colourSwatches.length - 1 )); if (selItem.typename == "PathItem") { selItem.fillColor = colourSwatches[swatchIndex].color; } else { selItem.pathItems[0].fillColor = colourSwatches[swatchIndex].color; } } } } } ```
2016/09/15
[ "https://Stackoverflow.com/questions/39512551", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1876246/" ]
Instead of picking swatches at random (that's where you lose control), do this: 1. Build an array of your *target* size (32) and fill it with the required swatches (12). You don't have to randomize this array. 2. For every object, pick a random entry. 3. Remove the picked entry from the array. 4. Loop until satisfied. I.e., untested, but something like this: ``` var targetArray = []; // fill with the set of required colors, times 2 for (i=0; i < 12; i++) { targetArray[2*i] = i; targetArray[2*i+1] = i; } // fill up to contain 32 items for (i=24; i<32; i++) targetArray[i] = Math.floor(Math.random() * colourSwatches.length); ``` (see [Getting random value from an array](https://stackoverflow.com/q/4550505/2564301) for that `random` expression.) Now you have an array containing the *indexes* for swatches to use. Loop over your objects and pick random items from the array until you are finished (which would be good) or you run out of items to pick (which would indicate your count of items to fill is not correct): ``` for (i = 0; i < myObjects.length; i++) { arrayIndex = Math.floor(Math.random() * targetArray.length); swatchIndex = targetArray[arrayIndex]; targetArray.splice (arrayIndex,1); selItem.fillColor = colourSwatches[swatchIndex].color; } ```
32 objects: [![32 boxes](https://i.stack.imgur.com/7PuSn.jpg)](https://i.stack.imgur.com/7PuSn.jpg) 12 colors: [![12 colors](https://i.stack.imgur.com/X1TTs.jpg)](https://i.stack.imgur.com/X1TTs.jpg) ``` var document = app.activeDocument; var objects = document.selection; // 32 objects var swatchColors = document.swatches.getSelected(); // 12 colors var colors = swatchColors; // 12 colors colors = colors.concat(swatchColors); // duplicate the 12 colors, 12*2 colors // add 8 random colors for (var i = 0; i < 8; i++) { // create random index in [0, 11] var randomIndex = Math.floor(Math.random() * swatchColors.length); // add the random color to colors array colors.push(swatchColors[randomIndex]); // remove the added color from the swatches so no extra duplicates swatchColors.splice(randomIndex, 1); } // now we have 32 objects and 32 colors // in colors array, there are (12 * 2) + 8 random colors for (var i = 0; i < objects.length; i++) { objects[i].fillColor = colors[i].color; } ``` After execution: [![Objects colored](https://i.stack.imgur.com/oqUW7.jpg)](https://i.stack.imgur.com/oqUW7.jpg) Objects are iterated from top to bottom, left to right. This is the `document.selection` order. So the first 24 colors are applied in the same order they are in swatches. You can shuffle the `colors` if you want a random order.
55,748,772
I'm new in python. I'm trying to reverse each word in the sentence. I wrote following code for that and it is working perfeclty. My code: [From answer] ``` import re str = "I am Mike!" def reverse_word(matchobj): return matchobj.group(1)[::-1] res = re.sub(r"([A-Za-z]+)", reverse_word, str) print(res) ``` But I want to add one condition in that..only words should reverse not any symbol.[ except alphanumerical words and words contains hyphen] Updated## Sample: input: "I am Mike! and123 my-age is 12" current output: "I ma ekiM! dna123 ym-ega si 12" required output: "I ma ekiM! 321dna ege-ym si 21"
2019/04/18
[ "https://Stackoverflow.com/questions/55748772", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2809967/" ]
The Regex: [([A-Za-z]+)](https://regex101.com/r/sx4v8u/1) You can use the character class `[A-Za-z]` for checking any word with one or more length, capture it then reverse the group 1 using a function using the [re.sub](https://docs.python.org/3.7/library/re.html#re.sub) function. ``` import re str = "I am Mike!" def reverse_word(matchobj): return matchobj.group(1)[::-1] res = re.sub(r"([A-Za-z]+)", reverse_word, str) print(res) ``` Outputting: ``` 'I ma ekiM!' ``` --- **Update:** You can [tweak the code](https://regex101.com/r/G76inZ/1) a little to acheive your results: ``` import re str = "I am Mike! and123 my-age is 12" def reverse_word(matchobj): hyphen_word_pattern = r"([A-Za-z]+)\-([A-Za-z]+)" match = re.search(hyphen_word_pattern, matchobj.group(1)) if match: return re.sub(hyphen_word_pattern, f"{match.group(2)[::-1]}-{match.group(1)[::-1]}", match.group(0)) else: return matchobj.group(1)[::-1] res = re.sub(r"([A-Za-z]+\-?[A-Za-z]+)", reverse_word, str) print(res) ``` Outputting: ``` I ma ekiM! dna123 ega-ym si 12 ```
One approach which might work would be to make an additional iteration over the list of words and use `re.sub` to move an optional *leading* punctuation character back to the end of the now reversed word: ``` s = "I am Mike!" split_s = s.split() r_word = [word[::-1] for word in split_s] r_word = [re.sub(r'^([^\s\w])(.*)$', '\\2\\1', i) for i in r_word] new_s = " ".join(r_word) print(new_s) I ma ekiM! ```
55,748,772
I'm new in python. I'm trying to reverse each word in the sentence. I wrote following code for that and it is working perfeclty. My code: [From answer] ``` import re str = "I am Mike!" def reverse_word(matchobj): return matchobj.group(1)[::-1] res = re.sub(r"([A-Za-z]+)", reverse_word, str) print(res) ``` But I want to add one condition in that..only words should reverse not any symbol.[ except alphanumerical words and words contains hyphen] Updated## Sample: input: "I am Mike! and123 my-age is 12" current output: "I ma ekiM! dna123 ym-ega si 12" required output: "I ma ekiM! 321dna ege-ym si 21"
2019/04/18
[ "https://Stackoverflow.com/questions/55748772", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2809967/" ]
Don't use re at all ```py def reverse_words_in_string(string): spl = string.split() for i, word in enumerate(spl): spl[i] = word[::-1] return ' '.join(spl) ``` gives 'I ma !ekiM 321dna ega-ym si 21'
One approach which might work would be to make an additional iteration over the list of words and use `re.sub` to move an optional *leading* punctuation character back to the end of the now reversed word: ``` s = "I am Mike!" split_s = s.split() r_word = [word[::-1] for word in split_s] r_word = [re.sub(r'^([^\s\w])(.*)$', '\\2\\1', i) for i in r_word] new_s = " ".join(r_word) print(new_s) I ma ekiM! ```
55,748,772
I'm new in python. I'm trying to reverse each word in the sentence. I wrote following code for that and it is working perfeclty. My code: [From answer] ``` import re str = "I am Mike!" def reverse_word(matchobj): return matchobj.group(1)[::-1] res = re.sub(r"([A-Za-z]+)", reverse_word, str) print(res) ``` But I want to add one condition in that..only words should reverse not any symbol.[ except alphanumerical words and words contains hyphen] Updated## Sample: input: "I am Mike! and123 my-age is 12" current output: "I ma ekiM! dna123 ym-ega si 12" required output: "I ma ekiM! 321dna ege-ym si 21"
2019/04/18
[ "https://Stackoverflow.com/questions/55748772", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2809967/" ]
The Regex: [([A-Za-z]+)](https://regex101.com/r/sx4v8u/1) You can use the character class `[A-Za-z]` for checking any word with one or more length, capture it then reverse the group 1 using a function using the [re.sub](https://docs.python.org/3.7/library/re.html#re.sub) function. ``` import re str = "I am Mike!" def reverse_word(matchobj): return matchobj.group(1)[::-1] res = re.sub(r"([A-Za-z]+)", reverse_word, str) print(res) ``` Outputting: ``` 'I ma ekiM!' ``` --- **Update:** You can [tweak the code](https://regex101.com/r/G76inZ/1) a little to acheive your results: ``` import re str = "I am Mike! and123 my-age is 12" def reverse_word(matchobj): hyphen_word_pattern = r"([A-Za-z]+)\-([A-Za-z]+)" match = re.search(hyphen_word_pattern, matchobj.group(1)) if match: return re.sub(hyphen_word_pattern, f"{match.group(2)[::-1]}-{match.group(1)[::-1]}", match.group(0)) else: return matchobj.group(1)[::-1] res = re.sub(r"([A-Za-z]+\-?[A-Za-z]+)", reverse_word, str) print(res) ``` Outputting: ``` I ma ekiM! dna123 ega-ym si 12 ```
Don't use re at all ```py def reverse_words_in_string(string): spl = string.split() for i, word in enumerate(spl): spl[i] = word[::-1] return ' '.join(spl) ``` gives 'I ma !ekiM 321dna ega-ym si 21'
53,661,415
I'm using the if() function in a copy operation for an Azure KeyVault: ``` "variables": { "users": 3, "user1": { "tenantId": "[variables('tenantId')]", "objectId": "abcd", "permissions": { "keys": [ "get" ], "secrets": [ "get" ], "certificates": [ "get" ] } }, "user2": { "tenantId": "[variables('tenantId')]", "objectId": "efgh", "permissions": { "keys": [ "get" ], "secrets": [ "get" ], "certificates": [ "get" ] } }, "user3": { "tenantId": "[variables('tenantId')]", "objectId": "ijkl", "permissions": { "secrets": [ "get" ] } }, "extraUsers": [ "[variables('user1')]", "[variables('user2')]", "[variables('user3')]" ] "resources": [ { "name": "myKeyVault", "type": "Microsoft.KeyVault/vaults", "apiVersion": "2018-02-14", "location": "some_location", "tags": { "displayName": "KeyVault" }, "properties": { "copy": [ { "name": "accessPolicies", "count": "[add(variables('users'), length(variables('extraUsers')))]", "input": { "tenantId": "[variables('tenantId')]", "objectId": "[if(less(copyIndex('myLoop'), variables('users')), reference(concat('Microsoft.Compute/virtualMachines/myVm', copyIndex('myLoop'), '/providers/Microsoft.ManagedIdentity/Identities/default'), '2015-08-31-PREVIEW').principalId, variables('extraUsers')[sub(copyIndex('myLoop'), variables('users'))].objectId)]", "permissions": "[if(less(copyIndex('myLoop'), variables('users')), json($null), variables('extraUsers')[sub(copyIndex('myLoop'), variables('users'))].permissions)]" } } ], ``` The above boils down to: ``` if((index < A), <some object>.principalId, myArray[index - A].objectId) ``` However, when I try to deploy it, I get an error that an index of -1 is not allowed. It seems that ARM evaluates both the true and false expressions, so of course the subtract operation produces a negative result in the false expression. However, according to the answer here, this should be fixed in all regions: [How the if() function executes in Azure Resource Manager Templates](https://stackoverflow.com/questions/49445384/how-the-if-function-executes-in-azure-resource-manager-templates) Anyone know why this is happening? I did notice that the latest API version for the AKV resource in ARM templates is 2018-02-14, which is well before when bmoore-msft in the above question mentions the bug was fixed. I'm not sure if the API version is an accurate indicator of when code was released, or if it's just a label.
2018/12/06
[ "https://Stackoverflow.com/questions/53661415", "https://Stackoverflow.com", "https://Stackoverflow.com/users/10757308/" ]
I tried again and it works now. I did discover some syntax errors in my code. I originally wrote: ``` "copy": [ { "name": "loopName", "count": 3, "input": { "name": accessPolicies", "properties": { /* accessPolicies properties */ } } } ] ``` I thought that copy.name was the name of the loop, and that copy.input.name was the name of the property to copy. In fact it should be: ``` "copy": [ { "name": accessPolicies", "count": 3, "input": { /* accessPolicies properties */ } } ] ``` The loop doesn't have a name. You just supply the name of the property to copy. I've updated the code in my question. However, even if I revert to the original wrong version, I don't get the same error about a negative index. Instead I get an error that a bad value was provided for "accessPolicies". So unfortunately, I'm not sure what was the root cause. It may have been my syntax error, some server-side issue, or a combination of both.
it means your condition evaluates to not what you think it evaluates. api version doesnt matter. also, this is the part that evaluates to -1 (as far as I understand): ``` sub(copyIndex('myLoop'), variables('users')) ```
53,661,415
I'm using the if() function in a copy operation for an Azure KeyVault: ``` "variables": { "users": 3, "user1": { "tenantId": "[variables('tenantId')]", "objectId": "abcd", "permissions": { "keys": [ "get" ], "secrets": [ "get" ], "certificates": [ "get" ] } }, "user2": { "tenantId": "[variables('tenantId')]", "objectId": "efgh", "permissions": { "keys": [ "get" ], "secrets": [ "get" ], "certificates": [ "get" ] } }, "user3": { "tenantId": "[variables('tenantId')]", "objectId": "ijkl", "permissions": { "secrets": [ "get" ] } }, "extraUsers": [ "[variables('user1')]", "[variables('user2')]", "[variables('user3')]" ] "resources": [ { "name": "myKeyVault", "type": "Microsoft.KeyVault/vaults", "apiVersion": "2018-02-14", "location": "some_location", "tags": { "displayName": "KeyVault" }, "properties": { "copy": [ { "name": "accessPolicies", "count": "[add(variables('users'), length(variables('extraUsers')))]", "input": { "tenantId": "[variables('tenantId')]", "objectId": "[if(less(copyIndex('myLoop'), variables('users')), reference(concat('Microsoft.Compute/virtualMachines/myVm', copyIndex('myLoop'), '/providers/Microsoft.ManagedIdentity/Identities/default'), '2015-08-31-PREVIEW').principalId, variables('extraUsers')[sub(copyIndex('myLoop'), variables('users'))].objectId)]", "permissions": "[if(less(copyIndex('myLoop'), variables('users')), json($null), variables('extraUsers')[sub(copyIndex('myLoop'), variables('users'))].permissions)]" } } ], ``` The above boils down to: ``` if((index < A), <some object>.principalId, myArray[index - A].objectId) ``` However, when I try to deploy it, I get an error that an index of -1 is not allowed. It seems that ARM evaluates both the true and false expressions, so of course the subtract operation produces a negative result in the false expression. However, according to the answer here, this should be fixed in all regions: [How the if() function executes in Azure Resource Manager Templates](https://stackoverflow.com/questions/49445384/how-the-if-function-executes-in-azure-resource-manager-templates) Anyone know why this is happening? I did notice that the latest API version for the AKV resource in ARM templates is 2018-02-14, which is well before when bmoore-msft in the above question mentions the bug was fixed. I'm not sure if the API version is an accurate indicator of when code was released, or if it's just a label.
2018/12/06
[ "https://Stackoverflow.com/questions/53661415", "https://Stackoverflow.com", "https://Stackoverflow.com/users/10757308/" ]
I tried again and it works now. I did discover some syntax errors in my code. I originally wrote: ``` "copy": [ { "name": "loopName", "count": 3, "input": { "name": accessPolicies", "properties": { /* accessPolicies properties */ } } } ] ``` I thought that copy.name was the name of the loop, and that copy.input.name was the name of the property to copy. In fact it should be: ``` "copy": [ { "name": accessPolicies", "count": 3, "input": { /* accessPolicies properties */ } } ] ``` The loop doesn't have a name. You just supply the name of the property to copy. I've updated the code in my question. However, even if I revert to the original wrong version, I don't get the same error about a negative index. Instead I get an error that a bad value was provided for "accessPolicies". So unfortunately, I'm not sure what was the root cause. It may have been my syntax error, some server-side issue, or a combination of both.
Ok, the problem you're running into is that vars are evaluated before copy and copy is evaluated before if - so you still need valid indexes in an if() statement. We might be able to fix that, but for the short-term you need another approach. In your case, because you have exactly 2 batches and you're creating the vault, you can you an addition "pass" on the vault to add more access policies. Essentially you can first create the vault and add the MSI access policies and then after that's finished you can add the extra users. If you needed more than 2 "passes" or you're not creating the vault, then you would have to use nested deployments to do multiple passes (which works, it's just more work). Here's a sample based on your snippet above: ``` { "name": "myKeyVault", "type": "Microsoft.KeyVault/vaults", "apiVersion": "2018-02-14", "location": "some_location", "tags": { "displayName": "KeyVault" }, "properties": { "copy": [ { "name": "myLoop", "count": "[variables('users')]", "input": { "name": "accessPolicies", "properties": { "tenantId": "[variables('tenantId')]", "objectId": "[reference(concat('Microsoft.Compute/virtualMachines/myVm', copyIndex('myLoop'), '/providers/Microsoft.ManagedIdentity/Identities/default'), '2015-08-31-PREVIEW').principalId]", "permissions": "[json('null')]" } } } ] } }, { "name": "[concat('myKeyVault', '/add')]", "type": "Microsoft.KeyVault/vaults/accessPolicies", "apiVersion": "2018-02-14", "location": "some_location", "dependsOn": [ "myKeyVault" ], "tags": { "displayName": "MoreAccessPolicies" }, "properties": { "copy": [ { "name": "myLoop2", "count": "[length(variables('extraUsers'))]", "input": { "name": "accessPolicies", "properties": { "tenantId": "[variables('tenantId')]", "objectId": "[variables('extraUsers')[copyIndex('myLoop2')].objectId]", "permissions": "[variables('extraUsers')[copyIndex('myLoop2')].permissions]" } } } ] } } ``` That help?
3,839,809
I've been trying to detect an iPhone or iPad purely by stylesheet. I tried the solution provided [here](http://iphone.wikidot.com/detection) by using @media handheld, only screen and (max-device-width: 480px) {. However, this doesnt seem to work. Any ideas?
2010/10/01
[ "https://Stackoverflow.com/questions/3839809", "https://Stackoverflow.com", "https://Stackoverflow.com/users/188363/" ]
This is how I handle iPhone (and similar) devices [not iPad]: In my CSS file: ``` @media only screen and (max-width: 480px), only screen and (max-device-width: 480px) { /* CSS overrides for mobile here */ } ``` In the head of my HTML document: ``` <meta name="viewport" content="width=device-width,initial-scale=1,user-scalable=no"> ```
You might want to try the solution from [this O'Reilly article](http://broadcast.oreilly.com/2010/04/using-css-media-queries-ipad.html). The important part are these CSS media queries: ``` <link rel="stylesheet" media="all and (max-device-width: 480px)" href="iphone.css"> <link rel="stylesheet" media="all and (min-device-width: 481px) and (max-device-width: 1024px) and (orientation:portrait)" href="ipad-portrait.css"> <link rel="stylesheet" media="all and (min-device-width: 481px) and (max-device-width: 1024px) and (orientation:landscape)" href="ipad-landscape.css"> <link rel="stylesheet" media="all and (min-device-width: 1025px)" href="ipad-landscape.css"> ```
3,839,809
I've been trying to detect an iPhone or iPad purely by stylesheet. I tried the solution provided [here](http://iphone.wikidot.com/detection) by using @media handheld, only screen and (max-device-width: 480px) {. However, this doesnt seem to work. Any ideas?
2010/10/01
[ "https://Stackoverflow.com/questions/3839809", "https://Stackoverflow.com", "https://Stackoverflow.com/users/188363/" ]
iPhone & iPod touch: ``` <link rel="stylesheet" media="only screen and (max-device-width: 480px)" href="../iphone.css" type="text/css" /> ``` iPhone 4 & iPod touch 4G: ``` <link rel="stylesheet" media="only screen and (-webkit-min-device-pixel-ratio: 2)" type="text/css" href="../iphone4.css" /> ``` iPad: ``` <link rel="stylesheet" media="only screen and (max-device-width: 1024px)" href="../ipad.css" type="text/css" /> ```
You might want to try the solution from [this O'Reilly article](http://broadcast.oreilly.com/2010/04/using-css-media-queries-ipad.html). The important part are these CSS media queries: ``` <link rel="stylesheet" media="all and (max-device-width: 480px)" href="iphone.css"> <link rel="stylesheet" media="all and (min-device-width: 481px) and (max-device-width: 1024px) and (orientation:portrait)" href="ipad-portrait.css"> <link rel="stylesheet" media="all and (min-device-width: 481px) and (max-device-width: 1024px) and (orientation:landscape)" href="ipad-landscape.css"> <link rel="stylesheet" media="all and (min-device-width: 1025px)" href="ipad-landscape.css"> ```
3,839,809
I've been trying to detect an iPhone or iPad purely by stylesheet. I tried the solution provided [here](http://iphone.wikidot.com/detection) by using @media handheld, only screen and (max-device-width: 480px) {. However, this doesnt seem to work. Any ideas?
2010/10/01
[ "https://Stackoverflow.com/questions/3839809", "https://Stackoverflow.com", "https://Stackoverflow.com/users/188363/" ]
You might want to try the solution from [this O'Reilly article](http://broadcast.oreilly.com/2010/04/using-css-media-queries-ipad.html). The important part are these CSS media queries: ``` <link rel="stylesheet" media="all and (max-device-width: 480px)" href="iphone.css"> <link rel="stylesheet" media="all and (min-device-width: 481px) and (max-device-width: 1024px) and (orientation:portrait)" href="ipad-portrait.css"> <link rel="stylesheet" media="all and (min-device-width: 481px) and (max-device-width: 1024px) and (orientation:landscape)" href="ipad-landscape.css"> <link rel="stylesheet" media="all and (min-device-width: 1025px)" href="ipad-landscape.css"> ```
Many devices with different screen sizes/ratios/resolutions have come out even in the last five years, including new types of iPhones and iPads. It would be very difficult to customize a website for each device. Meanwhile, media queries for `device-width`, `device-height`, and `device-aspect-ratio` have been deprecated, so they may not work in future browser versions. (Source: [MDN](https://developer.mozilla.org/en-US/docs/Web/CSS/@media#Media_features)) TLDR: Design based on browser widths, not devices. [Here's a good introduction to this topic](http://verekia.com/initializr/responsive-template/).
3,839,809
I've been trying to detect an iPhone or iPad purely by stylesheet. I tried the solution provided [here](http://iphone.wikidot.com/detection) by using @media handheld, only screen and (max-device-width: 480px) {. However, this doesnt seem to work. Any ideas?
2010/10/01
[ "https://Stackoverflow.com/questions/3839809", "https://Stackoverflow.com", "https://Stackoverflow.com/users/188363/" ]
This is how I handle iPhone (and similar) devices [not iPad]: In my CSS file: ``` @media only screen and (max-width: 480px), only screen and (max-device-width: 480px) { /* CSS overrides for mobile here */ } ``` In the head of my HTML document: ``` <meta name="viewport" content="width=device-width,initial-scale=1,user-scalable=no"> ```
iPhone & iPod touch: ``` <link rel="stylesheet" media="only screen and (max-device-width: 480px)" href="../iphone.css" type="text/css" /> ``` iPhone 4 & iPod touch 4G: ``` <link rel="stylesheet" media="only screen and (-webkit-min-device-pixel-ratio: 2)" type="text/css" href="../iphone4.css" /> ``` iPad: ``` <link rel="stylesheet" media="only screen and (max-device-width: 1024px)" href="../ipad.css" type="text/css" /> ```
3,839,809
I've been trying to detect an iPhone or iPad purely by stylesheet. I tried the solution provided [here](http://iphone.wikidot.com/detection) by using @media handheld, only screen and (max-device-width: 480px) {. However, this doesnt seem to work. Any ideas?
2010/10/01
[ "https://Stackoverflow.com/questions/3839809", "https://Stackoverflow.com", "https://Stackoverflow.com/users/188363/" ]
This is how I handle iPhone (and similar) devices [not iPad]: In my CSS file: ``` @media only screen and (max-width: 480px), only screen and (max-device-width: 480px) { /* CSS overrides for mobile here */ } ``` In the head of my HTML document: ``` <meta name="viewport" content="width=device-width,initial-scale=1,user-scalable=no"> ```
I use these: ``` /* Non-Retina */ @media screen and (-webkit-max-device-pixel-ratio: 1) { } /* Retina */ @media only screen and (-webkit-min-device-pixel-ratio: 1.5), only screen and (-o-min-device-pixel-ratio: 3/2), only screen and (min--moz-device-pixel-ratio: 1.5), only screen and (min-device-pixel-ratio: 1.5) { } /* iPhone Portrait */ @media screen and (max-device-width: 480px) and (orientation:portrait) { } /* iPhone Landscape */ @media screen and (max-device-width: 480px) and (orientation:landscape) { } /* iPad Portrait */ @media screen and (min-device-width: 481px) and (max-device-width: 1024px) and (orientation:portrait) { } /* iPad Landscape */ @media screen and (min-device-width: 481px) and (max-device-width: 1024px) and (orientation:landscape) { } ``` <http://zsprawl.com/iOS/2012/03/css-for-iphone-ipad-and-retina-displays/>
3,839,809
I've been trying to detect an iPhone or iPad purely by stylesheet. I tried the solution provided [here](http://iphone.wikidot.com/detection) by using @media handheld, only screen and (max-device-width: 480px) {. However, this doesnt seem to work. Any ideas?
2010/10/01
[ "https://Stackoverflow.com/questions/3839809", "https://Stackoverflow.com", "https://Stackoverflow.com/users/188363/" ]
This is how I handle iPhone (and similar) devices [not iPad]: In my CSS file: ``` @media only screen and (max-width: 480px), only screen and (max-device-width: 480px) { /* CSS overrides for mobile here */ } ``` In the head of my HTML document: ``` <meta name="viewport" content="width=device-width,initial-scale=1,user-scalable=no"> ```
Many devices with different screen sizes/ratios/resolutions have come out even in the last five years, including new types of iPhones and iPads. It would be very difficult to customize a website for each device. Meanwhile, media queries for `device-width`, `device-height`, and `device-aspect-ratio` have been deprecated, so they may not work in future browser versions. (Source: [MDN](https://developer.mozilla.org/en-US/docs/Web/CSS/@media#Media_features)) TLDR: Design based on browser widths, not devices. [Here's a good introduction to this topic](http://verekia.com/initializr/responsive-template/).
3,839,809
I've been trying to detect an iPhone or iPad purely by stylesheet. I tried the solution provided [here](http://iphone.wikidot.com/detection) by using @media handheld, only screen and (max-device-width: 480px) {. However, this doesnt seem to work. Any ideas?
2010/10/01
[ "https://Stackoverflow.com/questions/3839809", "https://Stackoverflow.com", "https://Stackoverflow.com/users/188363/" ]
iPhone & iPod touch: ``` <link rel="stylesheet" media="only screen and (max-device-width: 480px)" href="../iphone.css" type="text/css" /> ``` iPhone 4 & iPod touch 4G: ``` <link rel="stylesheet" media="only screen and (-webkit-min-device-pixel-ratio: 2)" type="text/css" href="../iphone4.css" /> ``` iPad: ``` <link rel="stylesheet" media="only screen and (max-device-width: 1024px)" href="../ipad.css" type="text/css" /> ```
I use these: ``` /* Non-Retina */ @media screen and (-webkit-max-device-pixel-ratio: 1) { } /* Retina */ @media only screen and (-webkit-min-device-pixel-ratio: 1.5), only screen and (-o-min-device-pixel-ratio: 3/2), only screen and (min--moz-device-pixel-ratio: 1.5), only screen and (min-device-pixel-ratio: 1.5) { } /* iPhone Portrait */ @media screen and (max-device-width: 480px) and (orientation:portrait) { } /* iPhone Landscape */ @media screen and (max-device-width: 480px) and (orientation:landscape) { } /* iPad Portrait */ @media screen and (min-device-width: 481px) and (max-device-width: 1024px) and (orientation:portrait) { } /* iPad Landscape */ @media screen and (min-device-width: 481px) and (max-device-width: 1024px) and (orientation:landscape) { } ``` <http://zsprawl.com/iOS/2012/03/css-for-iphone-ipad-and-retina-displays/>
3,839,809
I've been trying to detect an iPhone or iPad purely by stylesheet. I tried the solution provided [here](http://iphone.wikidot.com/detection) by using @media handheld, only screen and (max-device-width: 480px) {. However, this doesnt seem to work. Any ideas?
2010/10/01
[ "https://Stackoverflow.com/questions/3839809", "https://Stackoverflow.com", "https://Stackoverflow.com/users/188363/" ]
iPhone & iPod touch: ``` <link rel="stylesheet" media="only screen and (max-device-width: 480px)" href="../iphone.css" type="text/css" /> ``` iPhone 4 & iPod touch 4G: ``` <link rel="stylesheet" media="only screen and (-webkit-min-device-pixel-ratio: 2)" type="text/css" href="../iphone4.css" /> ``` iPad: ``` <link rel="stylesheet" media="only screen and (max-device-width: 1024px)" href="../ipad.css" type="text/css" /> ```
Many devices with different screen sizes/ratios/resolutions have come out even in the last five years, including new types of iPhones and iPads. It would be very difficult to customize a website for each device. Meanwhile, media queries for `device-width`, `device-height`, and `device-aspect-ratio` have been deprecated, so they may not work in future browser versions. (Source: [MDN](https://developer.mozilla.org/en-US/docs/Web/CSS/@media#Media_features)) TLDR: Design based on browser widths, not devices. [Here's a good introduction to this topic](http://verekia.com/initializr/responsive-template/).
3,839,809
I've been trying to detect an iPhone or iPad purely by stylesheet. I tried the solution provided [here](http://iphone.wikidot.com/detection) by using @media handheld, only screen and (max-device-width: 480px) {. However, this doesnt seem to work. Any ideas?
2010/10/01
[ "https://Stackoverflow.com/questions/3839809", "https://Stackoverflow.com", "https://Stackoverflow.com/users/188363/" ]
I use these: ``` /* Non-Retina */ @media screen and (-webkit-max-device-pixel-ratio: 1) { } /* Retina */ @media only screen and (-webkit-min-device-pixel-ratio: 1.5), only screen and (-o-min-device-pixel-ratio: 3/2), only screen and (min--moz-device-pixel-ratio: 1.5), only screen and (min-device-pixel-ratio: 1.5) { } /* iPhone Portrait */ @media screen and (max-device-width: 480px) and (orientation:portrait) { } /* iPhone Landscape */ @media screen and (max-device-width: 480px) and (orientation:landscape) { } /* iPad Portrait */ @media screen and (min-device-width: 481px) and (max-device-width: 1024px) and (orientation:portrait) { } /* iPad Landscape */ @media screen and (min-device-width: 481px) and (max-device-width: 1024px) and (orientation:landscape) { } ``` <http://zsprawl.com/iOS/2012/03/css-for-iphone-ipad-and-retina-displays/>
Many devices with different screen sizes/ratios/resolutions have come out even in the last five years, including new types of iPhones and iPads. It would be very difficult to customize a website for each device. Meanwhile, media queries for `device-width`, `device-height`, and `device-aspect-ratio` have been deprecated, so they may not work in future browser versions. (Source: [MDN](https://developer.mozilla.org/en-US/docs/Web/CSS/@media#Media_features)) TLDR: Design based on browser widths, not devices. [Here's a good introduction to this topic](http://verekia.com/initializr/responsive-template/).
67,954,206
I am simply trying to compare one character in a string to its neighbor, but I keep getting a string index out of range error. I can't figure this out. ``` s = 'azcbobobegghakl' current = "" previous = "" for letter in range(0,len(s)): if s[letter] <= s[letter+1]: current += s[letter] print(current) ``` Thanks
2021/06/13
[ "https://Stackoverflow.com/questions/67954206", "https://Stackoverflow.com", "https://Stackoverflow.com/users/16210783/" ]
You can put the image in the same working directory (in the same folder as your html file) and then use ``` <img src="./plot.png" alt="Stock price vs. predictions graph"> ``` The "./" is important as it signals that the image is in the current folder. You could also use a website like [www.linkpicture.com](http://www.linkpicture.com) to generate a link to host your image and then use that link in your img
Some web browsers automatically disable images from loading. Fixing this could be as simple as selecting “show all images” from the browser's settings menu. It's also worth checking if the device you're using has security software or extensions that could block images. Again you can use this tag for .png type photo ``` <img src="exampel.end"> ``` //use extension type .end instead of .png
67,954,206
I am simply trying to compare one character in a string to its neighbor, but I keep getting a string index out of range error. I can't figure this out. ``` s = 'azcbobobegghakl' current = "" previous = "" for letter in range(0,len(s)): if s[letter] <= s[letter+1]: current += s[letter] print(current) ``` Thanks
2021/06/13
[ "https://Stackoverflow.com/questions/67954206", "https://Stackoverflow.com", "https://Stackoverflow.com/users/16210783/" ]
You can put the image in the same working directory (in the same folder as your html file) and then use ``` <img src="./plot.png" alt="Stock price vs. predictions graph"> ``` The "./" is important as it signals that the image is in the current folder. You could also use a website like [www.linkpicture.com](http://www.linkpicture.com) to generate a link to host your image and then use that link in your img
I forgot to mention that I was using the Django framework and the html templates work much differently than regular html files do. In Django you must put the image in a static folder and then call if with Jinja like so: `<img src="{% static 'mysite/image.PNG' %}">`
55,438,697
I'm trying to play audio from an mp4 file using SDL2 and FFmpeg, and using `SDL_QueueAudio` seems much easier than setting up a callback. All solutions I've found, whether here or in the [dranger tutorials](http://dranger.com/ffmpeg/tutorial03.html), are deprecated or use callbacks. I tried browsing all questions with both the ffmpeg and sdl tags (there aren't many), to no avail. I tried converting the dranger tutorial to use non-deprecated calls but ran into the same problem. I'm using C, FFmpeg 4.1 and SDL 2.0.9. This is the setup for AVCodecContext and AVCodec: ```c int audioStream = -1; for (i = 0; i < formatContext->nb_streams; i++) { if (audioStream < 0 && formatContext->streams[i]->codecpar->codec_type == AVMEDIA_TYPE_AUDIO) { audioStream = i; } } AVCodecParameters *audioParams = formatContext->streams[audioStream]->codecpar; AVCodec *audioCodec = avcodec_find_decoder(audioParams->codec_id); AVCodecContext *audioCodecCtx = avcodec_alloc_context3(NULL); avcodec_open2(audioCodecCtx, audioCodec, NULL); SDL_Init(SDL_INIT_AUDIO) SDL_AudioSpec desired, obtained; SDL_zero(desired); SDL_zero(obtained); desired.freq = audioCodecCtx->sample_rate; desired.format = AUDIO_F32SYS; desired.channels = audioCodecCtx->channels; desired.silence = 0; desired.samples = AUDIO_BUFFER_SIZE; SDL_AudioDeviceID audioDevice = SDL_OpenAudioDevice(NULL, 0, &desired, &obtained, SDL_AUDIO_ALLOW_ANY_CHANGE); ``` This is the main packet decoding loop: ```c while (av_read_frame(formatContext, &packet) >= 0) { if (packet.stream_index == audioStream) { if (!avcodec_send_packet(audioCodecCtx, &packet)) { avcodec_receive_frame(audioCodecCtx, audioFrame); SDL_QueueAudio(audioDevice, audioFrame->data[0], audioFrame->linesize[0]); } } } ``` The audio plays at the correct speed but at a much higher pitch than what it actually is. I would like it to sound the same as in any media player. Edit: I just realized the test video has stereo audio but I'm only queueing `audioFrame.data[0]`, which I assume means I'm only playing one channel. I tried queueing `audioFrame.data[1]` which has data as well but it did not solve the problem. Am I correct and if so, how do I play both channels?
2019/03/31
[ "https://Stackoverflow.com/questions/55438697", "https://Stackoverflow.com", "https://Stackoverflow.com/users/11283900/" ]
May be too late to answer this question, but I faced the same problem and now I found the solution that works for me, so I'm posting this. The problem here is, probably, that the audio format decoded by FFmpeg is AV\_SAMPLE\_FMT\_FLTP (float planer) format where channels are stored separately like `frame->data[0]` and `frame->data[1]`. We need to convert it to a format which packs those channels into one array using swr\_convert() And here's my solution. 1. SwrContext set up ```cpp SwrContext *resampler = swr_alloc_set_opts(NULL, audioCodecCtx->channel_layout, AV_SAMPLE_FMT_S16, 44100, audioCodecCtx->channel_layout, audioCodecCtx->sample_fmt, audioCodecCtx->sample_rate, 0, NULL); swr_init(resampler); ``` 2. SDL Audio set up ```cpp SDL_AudioDeviceID dev; SDL_AudioSpec want, have; SDL_zero(want); SDL_zero(have); want.freq = 44100; want.channels = audioCodecCtx->channels; want.format = AUDIO_S16SYS; dev = SDL_OpenAudioDevice(NULL, 0, &want, &have, 0); SDL_PauseAudioDevice(dev, 0); ``` finally the decoding loop ```cpp int ret = 0; AVPacket *packet = av_packet_alloc(); AVFrame *frame = av_frame_alloc(); AVFrame *audioframe = av_frame_alloc(); while (true){ ret = av_read_frame(formatContext, packet); if (ret < 0) break; AVStream *stream = formatContext->streams[packet->stream_index]; if (stream->codecpar->codec_type == AVMEDIA_TYPE_AUDIO){ ret = avcodec_send_packet(audioCodecCtx, packet); while (ret >= 0){ ret = avcodec_receive_frame(audioCodecCtx, frame); if (ret >= 0){ int dst_samples = frame->channels * av_rescale_rnd( swr_get_delay(resampler, frame->sample_rate) + frame->nb_samples, 44100, frame->sample_rate, AV_ROUND_UP); uint8_t *audiobuf = NULL; ret = av_samples_alloc(&audiobuf, NULL, 1, dst_samples, AV_SAMPLE_FMT_S16, 1); dst_samples = frame->channels * swr_convert( resampler, &audiobuf, dst_samples, (const uint8_t**) frame->data, frame->nb_samples); ret = av_samples_fill_arrays(audioframe->data, audioframe->linesize, audiobuf, 1, dst_samples, AV_SAMPLE_FMT_S16, 1); SDL_QueueAudio(dev, audioframe->data[0], audioframe->linesize[0]); } } } } ```
What worked for me was adjusting the frequency. Try changing the frequency to something like `audioCodecCtx->sample_rate * 0.5`.
26,402,058
I have a carousel slider where i want to give model name to each image.So i use a `<div>` and put text into div. But the text is not displaying though background color of this div is visible.So need help .please.How to display the text? my code sample goes here **html** ``` <link href="bootstrap.min.css" rel="stylesheet"> <div id="body-content"> <div class="carousel-nano" > <div id="demo5" class="scroll-img"> <ul> <li> <a href="" target="_blank"> <img src="jsfiddle.net/img/logo.png"/> <div style="color:red;background-color:#000;">Text goes here</div> </a> </li> </ul> </div> </div> </div> ``` **css** ``` #body-content .scroll-img { border: 2px solid #CCC; width: 890px; height: 155px; overflow: hidden; font-size: 0; margin-top: 2px; } #body-content .scroll-img ul { margin: 0; height: 58px !important; background:#123456; } #body-content .scroll-img ul li a img{ width: 140px; height: 100px; margin: 0; } #body-content .scroll-img ul li { display: inline-block; margin: 0px 0 0px 0px; border-right: 10px solid #EEE; } #body-content #demo5.scroll-img ul { width: 1500px; } #body-content #demo5-btn { width: 680px; padding-top: 10px; } #body-content .carousel-nano{ margin:0 auto; padding:0px; text-align:center; width:960px; } #search-image{ margin: 0px auto; padding: 0px; float: left; width: 66px; height: 103px; } ``` [jsfiddle](http://jsfiddle.net/c2yxsrzg/)
2014/10/16
[ "https://Stackoverflow.com/questions/26402058", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3926727/" ]
Try to increase font-size here ``` #body-content .scroll-img { font-size : 12px; } ``` You have `font-size` zero in your fiddle.See updated [**FIDDLE**](http://jsfiddle.net/c2yxsrzg/1/).
Change ``` #body-content .scroll-img { border: 2px solid #CCC; width: 890px; height: 155px; overflow: hidden; font-size: 0; margin-top: 2px; } ``` to ``` #body-content .scroll-img { border: 2px solid #CCC; width: 890px; height: 155px; overflow: hidden; font-size: 14px; margin-top: 2px; } ```
26,402,058
I have a carousel slider where i want to give model name to each image.So i use a `<div>` and put text into div. But the text is not displaying though background color of this div is visible.So need help .please.How to display the text? my code sample goes here **html** ``` <link href="bootstrap.min.css" rel="stylesheet"> <div id="body-content"> <div class="carousel-nano" > <div id="demo5" class="scroll-img"> <ul> <li> <a href="" target="_blank"> <img src="jsfiddle.net/img/logo.png"/> <div style="color:red;background-color:#000;">Text goes here</div> </a> </li> </ul> </div> </div> </div> ``` **css** ``` #body-content .scroll-img { border: 2px solid #CCC; width: 890px; height: 155px; overflow: hidden; font-size: 0; margin-top: 2px; } #body-content .scroll-img ul { margin: 0; height: 58px !important; background:#123456; } #body-content .scroll-img ul li a img{ width: 140px; height: 100px; margin: 0; } #body-content .scroll-img ul li { display: inline-block; margin: 0px 0 0px 0px; border-right: 10px solid #EEE; } #body-content #demo5.scroll-img ul { width: 1500px; } #body-content #demo5-btn { width: 680px; padding-top: 10px; } #body-content .carousel-nano{ margin:0 auto; padding:0px; text-align:center; width:960px; } #search-image{ margin: 0px auto; padding: 0px; float: left; width: 66px; height: 103px; } ``` [jsfiddle](http://jsfiddle.net/c2yxsrzg/)
2014/10/16
[ "https://Stackoverflow.com/questions/26402058", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3926727/" ]
Try to increase font-size here ``` #body-content .scroll-img { font-size : 12px; } ``` You have `font-size` zero in your fiddle.See updated [**FIDDLE**](http://jsfiddle.net/c2yxsrzg/1/).
the thing i have noticed that, you have mentioned **font-size=0;** which is causing the problem to you. ***font-size is the attribute to set the size of the text you want to print on the screen as a result***. so increase **font-size=5px;** atleast to see the result. Rest is fine. Thanks & Keep coding. :)
70,851,918
If my string is: ``` mary lamb The beast the castle THE large lake ``` I want to produce: ``` mary lamb The beast the castle The large lake ``` If I do `(?i)(?:(.*the))` then it only splits on the last the but i want to split on each "the" regardless of case.
2022/01/25
[ "https://Stackoverflow.com/questions/70851918", "https://Stackoverflow.com", "https://Stackoverflow.com/users/17183812/" ]
so the best way to make your video responsive without any black sidebars, is to nest your iframe within a parent div. You will make this parent container "hold" the video using `position: relative` with the iframe displaying using `position: absolute`. The key declaration for the parent element is `padding: 56.25%`. This keeps the elements to 16:9 ratio and will make your video responsive. ``` .video-container { position: relative; padding-bottom: 56.25%; overflow: hidden; max-width: 100%; height: auto; } .video-container iframe, .video-container object, .video-container embed { position: absolute; top: 0; left: 0; width: 100%; height: 100%; } ``` <https://jsfiddle.net/EdgarAlexPoe/gak5cfsh/3/>
We can use the `aspect-ratio` CSS property to achieve the same result as [@EdgarAlexPoe](https://stackoverflow.com/a/70851961/11361359) with less math. CSS: ``` .video-container { aspect-ratio: 16/9; } .video-container iframe { width: 100%; height: 100%; } ``` HTML ``` <div class="video-container"> <iframe width="560" height="315" src="https://www.youtube.com/embed/dQw4w9WgXcQ" title="YouTube video player" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe> </div> ``` <https://codepen.io/trevorleeman/pen/YzerBKa>
37,760,093
Well, I recently see whatsapp and tinder application. The "change profile picture" option is the same besides the button over. How we can do this? Is there any lib? or shape to do this ? [![enter image description here](https://i.stack.imgur.com/JDAz9.png)](https://i.stack.imgur.com/JDAz9.png)
2016/06/11
[ "https://Stackoverflow.com/questions/37760093", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
If you expand the macro, the line ``` j = product(i++); ``` becomes ``` j = i++*i++; ``` and the line ``` k = product(++i); ``` becomes ``` k = ++i*++i; ``` Both these lines are subject to undefined behavior. You can try to make sense of it for one run of the program but the results are not guaranteed to be same with a different compiler or even the same compiler with different compiler flags. When you use a function call instead of a macro, the behavior of the code is more straight forward. The line ``` j = product(i++); ``` is equivalent to: ``` int temp = i; j = product(temp); i++; ``` The line ``` k = product(++i); ``` is equivalent to: ``` ++i; k = product(i); ``` Hence, there are no problems when a function is used instead of a macro.
The output you expect will require you to change the macro to a function ``` #include <stdio.h> int product(int a) { return a * a; } int main() { int i = 3, j, k; j = product(i++); k = product(++i); printf("%d %d\n", j, k); return 0; } ``` **Output** ``` 9 25 ``` Since macro unpacks inline, the value of `i` changes in the `main` function's callframe and you get an unexpected result.
59,604,462
I have been fiddling with my navigation menu for a while now with no luck. I am uncertain why and would appreciate any and all insight. I do not think the script is at fault, but I have no idea why it does not show the hamburger icon when the screen is smaller. I feel like I have tried everything by now, it is really starting to give me quite the headache. It should be so simple, but it refuses to work. The menu is, quite simply, supposed to show the hamburger icon on smaller screens, and when you click on it, the full nav-menu slides down. The nav-list does disappear but there is no hamburger-icon so I can´t make it reappear on smaller screens. LINK TO MY CODEPEN: <https://codepen.io/Pinchofginger/pen/eYmydBo> ```html <div class="nav"> <nav class="main-navigation"> <a href="#"><img id="logo"src="https://www.vindrosen-huset.dk/media/zoo/images/Angstforeningen_29df0951c1c6886d2b89cb5249a05da4.png" alt="alt tekst"></a> <div class="menu-list"> <a href="#">Hjem &nbsp;<i class="fas fa-home"></i></a></a> <div class="subnav"> <a href="www.angstforeningen.dk/index.php?page=hvorfor-en-angstforening">Emner på siden &nbsp; <i class="fas fa-list"></i></a></div> <div class="subnav"> <a href="www.angstforeningen.dk/uploads/tryksager/pjecer/Panikangst.pdf">Folder &nbsp;<i class="fas fa-file-download"></i></a></div> <div class="subnav"> <a href="tegn-paa-smerte.html">Kontakt os &nbsp;<i class="fas fa-envelope"></i> </a></div> <i id="mobile-menu" class="fas fa-bars"></i> </nav> </div></div> <!-- Ikon kit --> <script src="https://kit.fontawesome.com/52c7af8f48.js" crossorigin="anonymous"></script> ``` ```css .nav { background-color: #144e75; } #logo { margin-top: -35%; } .main-navigation { letter-spacing: .1em; /* Rummet mellem bogstaver */ height: 20px; display: flex; /* flexbox */ justify-content: space-between; /* Distribuere delene ligeligt på pladsen */ } .main-navigation img { height: 60px; } .main-navigation a { padding: 30px 10px; float: left; color: #f6933b; font-weight: bold; margin: 0 15px; } .main-navigation a:hover { color: white; } #mobile-menu { display: none; font-size: 25px; margin-right: 10px; } .subnav { float: left; overflow: hidden; } @media only screen and (max-width: 900px) { #mobile-menu { display: flex; } .main-navigation a { float: none; } .menu-list { display: none; position: absolute; left: 0; top: 80px; border-top: 5px solid #0072ce; border-bottom: 5px solid #0072ce; width: 100%; background-color: #fff; } .menu-list a { display: block; padding: 16px; } .subnav { float: none; display: inline; } } ``` ```js $("#mobile-menu").click(function() { $(".menu-list").slideToggle(); $("a").click(function() { $(".menu-list").slideUp(); }); }); ```
2020/01/05
[ "https://Stackoverflow.com/questions/59604462", "https://Stackoverflow.com", "https://Stackoverflow.com/users/9157388/" ]
in your structure the hamburger is a child to the div that has class of menu-list and because you hide menu-list you also hide all childs so you need to get it out to display ```js $("#mobile-menu").click(function() { $(".menu-list").slideToggle(); $("a").click(function() { $(".menu-list").slideUp(); }); }); ``` ```css .nav { background-color: #144e75;} #logo {margin-top: -35%;} .main-navigation { letter-spacing: 0.1em; /*Rummet mellem bogstaver*/ height: 20px; display: flex; /*flexbox*/ justify-content: space-between;/*Distribuere delene ligeligt på pladsen*/ } .main-navigation img { height: 60px; } .main-navigation a { padding: 30px 10px; float: left; color: #f6933b; font-weight: bold; margin: 0 15px; } .main-navigation a:hover { color: white; } #mobile-menu { display: none; font-size: 25px; margin-right: 10px; } .subnav { float: left; overflow: hidden; } @media only screen and (max-width: 900px) { #mobile-menu { display: flex;flex-direction:row-reverse; } .main-navigation a { float: none; } .menu-list { display: none; position: absolute; left: 0; top: 80px; border-top: 5px solid #0072ce; border-bottom: 5px solid #0072ce; width: 100%; background-color: #fff; } .menu-list a { display: block; padding: 16px; } .subnav { float: none; display: inline; } } ``` ```html <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <div class="nav"> <nav class="main-navigation"> <a href="#"><img id="logo"src="https://www.vindrosen-huset.dk/media/zoo/images/Angstforeningen_29df0951c1c6886d2b89cb5249a05da4.png" alt="alt tekst"></a> <div class="menu-list"> <a href="#">Hjem &nbsp;<i class="fas fa-home"></i></a></a> <div class="subnav"> <a href="www.angstforeningen.dk/index.php?page=hvorfor-en-angstforening">Emner på siden &nbsp; <i class="fas fa-list"></i></a></div> <div class="subnav"> <a href="www.angstforeningen.dk/uploads/tryksager/pjecer/Panikangst.pdf">Folder &nbsp;<i class="fas fa-file-download"></i></a></div> <div class="subnav"> <a href="tegn-paa-smerte.html">Kontakt os &nbsp;<i class="fas fa-envelope"></i> </a></div> </nav> </div> <i id="mobile-menu" class="fas fa-bars"></i> </div> <!-- Ikon kit --> <script src="https://kit.fontawesome.com/52c7af8f48.js" crossorigin="anonymous"></script> ```
In your Codepen, `#mobile-menu` is inside `#menulist` which has `display: none`. Move it out and it is visible
59,604,462
I have been fiddling with my navigation menu for a while now with no luck. I am uncertain why and would appreciate any and all insight. I do not think the script is at fault, but I have no idea why it does not show the hamburger icon when the screen is smaller. I feel like I have tried everything by now, it is really starting to give me quite the headache. It should be so simple, but it refuses to work. The menu is, quite simply, supposed to show the hamburger icon on smaller screens, and when you click on it, the full nav-menu slides down. The nav-list does disappear but there is no hamburger-icon so I can´t make it reappear on smaller screens. LINK TO MY CODEPEN: <https://codepen.io/Pinchofginger/pen/eYmydBo> ```html <div class="nav"> <nav class="main-navigation"> <a href="#"><img id="logo"src="https://www.vindrosen-huset.dk/media/zoo/images/Angstforeningen_29df0951c1c6886d2b89cb5249a05da4.png" alt="alt tekst"></a> <div class="menu-list"> <a href="#">Hjem &nbsp;<i class="fas fa-home"></i></a></a> <div class="subnav"> <a href="www.angstforeningen.dk/index.php?page=hvorfor-en-angstforening">Emner på siden &nbsp; <i class="fas fa-list"></i></a></div> <div class="subnav"> <a href="www.angstforeningen.dk/uploads/tryksager/pjecer/Panikangst.pdf">Folder &nbsp;<i class="fas fa-file-download"></i></a></div> <div class="subnav"> <a href="tegn-paa-smerte.html">Kontakt os &nbsp;<i class="fas fa-envelope"></i> </a></div> <i id="mobile-menu" class="fas fa-bars"></i> </nav> </div></div> <!-- Ikon kit --> <script src="https://kit.fontawesome.com/52c7af8f48.js" crossorigin="anonymous"></script> ``` ```css .nav { background-color: #144e75; } #logo { margin-top: -35%; } .main-navigation { letter-spacing: .1em; /* Rummet mellem bogstaver */ height: 20px; display: flex; /* flexbox */ justify-content: space-between; /* Distribuere delene ligeligt på pladsen */ } .main-navigation img { height: 60px; } .main-navigation a { padding: 30px 10px; float: left; color: #f6933b; font-weight: bold; margin: 0 15px; } .main-navigation a:hover { color: white; } #mobile-menu { display: none; font-size: 25px; margin-right: 10px; } .subnav { float: left; overflow: hidden; } @media only screen and (max-width: 900px) { #mobile-menu { display: flex; } .main-navigation a { float: none; } .menu-list { display: none; position: absolute; left: 0; top: 80px; border-top: 5px solid #0072ce; border-bottom: 5px solid #0072ce; width: 100%; background-color: #fff; } .menu-list a { display: block; padding: 16px; } .subnav { float: none; display: inline; } } ``` ```js $("#mobile-menu").click(function() { $(".menu-list").slideToggle(); $("a").click(function() { $(".menu-list").slideUp(); }); }); ```
2020/01/05
[ "https://Stackoverflow.com/questions/59604462", "https://Stackoverflow.com", "https://Stackoverflow.com/users/9157388/" ]
in your structure the hamburger is a child to the div that has class of menu-list and because you hide menu-list you also hide all childs so you need to get it out to display ```js $("#mobile-menu").click(function() { $(".menu-list").slideToggle(); $("a").click(function() { $(".menu-list").slideUp(); }); }); ``` ```css .nav { background-color: #144e75;} #logo {margin-top: -35%;} .main-navigation { letter-spacing: 0.1em; /*Rummet mellem bogstaver*/ height: 20px; display: flex; /*flexbox*/ justify-content: space-between;/*Distribuere delene ligeligt på pladsen*/ } .main-navigation img { height: 60px; } .main-navigation a { padding: 30px 10px; float: left; color: #f6933b; font-weight: bold; margin: 0 15px; } .main-navigation a:hover { color: white; } #mobile-menu { display: none; font-size: 25px; margin-right: 10px; } .subnav { float: left; overflow: hidden; } @media only screen and (max-width: 900px) { #mobile-menu { display: flex;flex-direction:row-reverse; } .main-navigation a { float: none; } .menu-list { display: none; position: absolute; left: 0; top: 80px; border-top: 5px solid #0072ce; border-bottom: 5px solid #0072ce; width: 100%; background-color: #fff; } .menu-list a { display: block; padding: 16px; } .subnav { float: none; display: inline; } } ``` ```html <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <div class="nav"> <nav class="main-navigation"> <a href="#"><img id="logo"src="https://www.vindrosen-huset.dk/media/zoo/images/Angstforeningen_29df0951c1c6886d2b89cb5249a05da4.png" alt="alt tekst"></a> <div class="menu-list"> <a href="#">Hjem &nbsp;<i class="fas fa-home"></i></a></a> <div class="subnav"> <a href="www.angstforeningen.dk/index.php?page=hvorfor-en-angstforening">Emner på siden &nbsp; <i class="fas fa-list"></i></a></div> <div class="subnav"> <a href="www.angstforeningen.dk/uploads/tryksager/pjecer/Panikangst.pdf">Folder &nbsp;<i class="fas fa-file-download"></i></a></div> <div class="subnav"> <a href="tegn-paa-smerte.html">Kontakt os &nbsp;<i class="fas fa-envelope"></i> </a></div> </nav> </div> <i id="mobile-menu" class="fas fa-bars"></i> </div> <!-- Ikon kit --> <script src="https://kit.fontawesome.com/52c7af8f48.js" crossorigin="anonymous"></script> ```
I just move `#mobile-menu` outside the `.menulist` div. Reason behind why it not appear is `.menu-list` already display none and hamburger-icon inside the `.menu-list` that why is not appear. ```js $("#mobile-menu").click(function() { $(".menu-list").slideToggle(); $("a").click(function() { $(".menu-list").slideUp(); }); }); ``` ```css .nav { background-color: #144e75;} #logo {margin-top: -35%;} .main-navigation { letter-spacing: 0.1em; /*Rummet mellem bogstaver*/ height: 20px; display: flex; /*flexbox*/ justify-content: space-between;/*Distribuere delene ligeligt på pladsen*/ } .main-navigation img { height: 60px; } .main-navigation a { padding: 30px 10px; float: left; color: #f6933b; font-weight: bold; margin: 0 15px; } .main-navigation a:hover { color: white; } #mobile-menu { display: none; font-size: 25px; margin-right: 10px; } .subnav { float: left; overflow: hidden; } @media only screen and (max-width: 900px) { #mobile-menu { display: flex; } .main-navigation a { float: none; } .menu-list { display: none; position: absolute; left: 0; top: 80px; border-top: 5px solid #0072ce; border-bottom: 5px solid #0072ce; width: 100%; background-color: #fff; } .menu-list a { display: block; padding: 16px; } .subnav { float: none; display: inline; } } ``` ```html <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <div class="nav"> <nav class="main-navigation"> <a href="#"><img id="logo"src="https://www.vindrosen-huset.dk/media/zoo/images/Angstforeningen_29df0951c1c6886d2b89cb5249a05da4.png" alt="alt tekst"></a> <div class="menu-list"> <a href="#">Hjem &nbsp;<i class="fas fa-home"></i></a></a> <div class="subnav"> <a href="www.angstforeningen.dk/index.php?page=hvorfor-en-angstforening">Emner på siden &nbsp; <i class="fas fa-list"></i></a></div> <div class="subnav"> <a href="www.angstforeningen.dk/uploads/tryksager/pjecer/Panikangst.pdf">Folder &nbsp;<i class="fas fa-file-download"></i></a></div> <div class="subnav"> <a href="tegn-paa-smerte.html">Kontakt os &nbsp;<i class="fas fa-envelope"></i> </a></div> </nav> </div> <i id="mobile-menu" class="fas fa-bars"></i> </div> <!-- Ikon kit --> <script src="https://kit.fontawesome.com/52c7af8f48.js" crossorigin="anonymous"></script> ```
486,299
I have a simple wifi temp/humidity sensor I've set up on an adafruit breadboard, and I'd like to transfer to a perma-proto type board, but the solderable boards I have are a slightly different layout than the adafruit board. There do not appear to be any power rails on the edges so I'm not sure how I may need to rework the circuit for it to function. I'm very much a tinkerer/new to circuits like this so I'm trying to avoid connecting anything in a way that might damage my ESP8266. ![adafruit board next to solderable board](https://i.imgur.com/uWNmLe7.jpg)
2020/03/15
[ "https://electronics.stackexchange.com/questions/486299", "https://electronics.stackexchange.com", "https://electronics.stackexchange.com/users/87637/" ]
Yes, that solderable board is different from the breadboard. As you say, there are no power rails on it, so if you're going to use it, you need to add wires for power. Or you can buy a board that more closely [imitates the breadboard](https://www.sparkfun.com/products/12070).
Power, ground, data, and a pull-up on data, right? Skin the wires, solder in the resistor, cover the whole thing with heat-shrink.